0

Here's my code.

/**
 * Load an Object from disk.
 */
public static <T> T load(String path) throws IOException {
    File entry = new TFile(path);
    char[] chars = new char[(int)entry.length()];
    InputStream in = new TFileInputStream(entry);
    BufferedReader fIn = new BufferedReader(new InputStreamReader(in, "UTF-8"));
    fIn.read(chars);
    fIn.close();
    //converts the string to an object using the Base64Coder
    return decode(new String(chars));
}


/**
 * Save an object to disk as a compressed file.
 */
public static void save(String path, Serializable o) {
    //converts the object to a string
    String content = encode(o);
    File entry = new TFile(path);
    Writer writer;
    try {
        writer = new TFileWriter(entry);
        writer.write(content);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

I'm trying to use TrueVFS to load and save objects from memory into a compressed file. This code here works, but only when i reference the file directly. (So the path given is something like "data.zip/data Entries/0/2/data.txt")

The problem i have is that as soon as i try to put this file into a path (So the path given is something like "Save Files/World 1/data.zip/dataEntry/0/2/data.txt"), i get a NoSuchFileException error.

How should i go about putting my archives into a specified folder?

Duckie
  • 1
  • 1

1 Answers1

0

Solved the problem, here's the new code.

/**
 * Load an Object from disk.
 */
public static <T> T load(String directory, String fileName, String archiveDirectory) throws IOException {
    File entry = new TFile(directory + fileName, archiveDirectory);
    char[] chars = new char[(int)entry.length()];
    InputStream in = new TFileInputStream(entry);
    BufferedReader fIn = new BufferedReader(new InputStreamReader(in, "UTF-8"));
    fIn.read(chars);
    fIn.close();
    return decode(new String(chars));
}


/**
 * Save an object to disk as a compressed file.
 */
public static void save(String directory, String fileName, String archiveDirectory, Serializable o) {
    String content = encode(o);
    Path parent = new TPath(directory);
    Writer writer;
    try {
        if (!Files.exists(parent)) {
            Files.createDirectory(parent);
        }
        File entry = new TFile(directory + fileName, archiveDirectory);
        writer = new TFileWriter(entry);
        writer.write(content);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Duckie
  • 1
  • 1