使用PrintWriter写入文件
import java.io.FileNotFoundException;// 来自 n o w j a v a . c o m import java.io.PrintWriter; import java.util.Scanner; public class Ejercicio1 { public static void Main(String[] args){ Scanner sc = new Scanner(System.in); String text; PrintWriter result = null; try{ result = new PrintWriter("a.txt"); System.out.println("introduce texto:");// 来 自 N o w J a v a . c o m - 时 代 Java text = sc.nextLine(); while (text.compareTo("fin") != 0) { result.println(text); text = sc.nextLine(); }