<!-- lang: java --> /**經過路徑 保存文件 保存是按格式保存 */ public void saveFile(String path){ File file = new File(path); try { String text = textArea.getText(); PrintWriter out = new PrintWriter(new FileOutputStream(file), true); String[] lines = text.trim().split("\n"); for (String line : lines) out.println(line); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }