0

我正在构建一个 GUI,它从所有客户信息的文本文件中读取,然后在我的 GUI 中显示信息。我希望让客户通过我的 GUI 更改他或她的信息,然后通过点击“保存更改”按钮,我能够将所有这些更改保存到我正在读取的同一个文本文件中。我是 FileReader/FileWriter 和 BufferedReader/PrinterWriter 的新手。有人可以告诉我如何设计吗?非常感谢!

4

1 回答 1

1

如果您使用的是 Java 7,那就容易多了。例如:

public static void main(String[] args) throws IOException {

    // You get this file with JFileChooser
    File selectedFile = new File("file.txt");

    // Read file and close file.
    List<String> lines = Files.readAllLines(selectedFile.toPath(),
            StandardCharsets.UTF_8);

    // Modify some in the lines...

    // This replace the contents and close the file
    Files.write(selectedFile.toPath(), lines, StandardCharsets.UTF_8);

}
于 2013-11-09T15:53:28.480 回答