문제

    try {
        File file = new File(filepath+"temp.txt");
        if (!file.exists()) {
            file.createNewFile();
        }
        FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(input+"\n");
        bw.close();
        fw.close();
    } catch(Exception e) { e.printStackTrace(); }

Every time the user enters something, I want it recorded into a text file. The problem is that every time the user enters something, its recorded on the same line. How do I edit this part of my code to write to a file, then start a new line so that next time it writes to a new line.

도움이 되었습니까?

해결책

you can use that

bw.write(input);
bw.newLine();

Try to google first or it is even better read the javadocs http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top