سؤال

I am trying to write out some data to a file. However, every time I restart my program, I think it is overwriting the original file (making a new one?) Here is a snippet of code where I instantiate things. Is there something I can change so that the file doesn't get overwritten everytime? something like if file.doesExist??

try {
        File root = Environment.getExternalStorageDirectory();
        if(root.canWrite()){
        File highscoresFile = new File(root, "names.txt");
        FileWriter writer = new FileWriter(highscoresFile);
        BufferedWriter out = new BufferedWriter(writer);
        //out.newLine();
        out.append(name);
        out.close();
        }
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

لا يوجد حل صحيح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top