Java Utililty Methods File Save

List of utility methods to do File Save

Description

The list of methods to do File Save are organized into topic(s).

Method

voidsaveIntArray(int[] array, PrintStream out)
save Int Array
int dim = array.length;
out.println(dim);
for (int i = 0; i < dim; i++) {
    out.print(array[i]);
    if (i != dim - 1) {
        out.print(" ");
out.println();
voidSaveIntFile(int[] list, String filename)
Save the specified array of ints in the specified file IN PC FORMAT.
if (list == null)
    throw new IllegalArgumentException("Array of ints is null");
if (filename == null)
    throw new IllegalArgumentException("Filename String is NULL");
byte[] buffer = new byte[4 * list.length];
for (int i = 0; i < list.length; i++)
    setInt_32(list[i], buffer, 4 * i);
try {
...
StringsaveStreamAsString(InputStream is)
Read data from Input Stream and save it as a String.
return toString(is, ENCODING);
voidsaveStringDoubleMap(Map map, int dim, PrintStream out)
save String Double Map
out.println(map.size() + " " + dim);
for (Entry<String, double[]> entry : map.entrySet()) {
    out.println(entry.getKey());
    for (int i = 0; i < dim; i++) {
        out.print(entry.getValue()[i]);
        if (i != dim - 1) {
            out.print(" ");
    out.println();
voidsaveToInputStream(ByteArrayInputStream in, OutputStream out)
save To Input Stream
try {
    byte[] buffer = new byte[1024];
    int read = 0;
    while (true) {
        read = in.read(buffer);
        if (read <= 0)
            break;
        out.write(buffer, 0, read);
...
voidsaveTrecOneEntry(BufferedWriter trecFile, String topicId, String docId, int docPos, float score, String runId)
Save positions, scores, etc information for a single retrieved documents.
trecFile.write(String.format("%s\tQ0\t%s\t%d\t%f\t%s%s", topicId, docId, docPos, score, runId, NL));