保存文件对象: ```java File file = new File("path/to/file.txt"); try { FileWriter writer = new FileWriter(file); writer.write("Hello World!"); writer.close(); } catch (IOException e) { e.printStackTrace(); } ``` 打开文件对象: ```java File file = new File("path/to/file.txt"); try { Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { String line = scanner.nextLine(); System.out.println(line); } scanner.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } ```