JAVA简单的文件I/O操作实例

如果只是对文件进行普通的读写,可以不用文件流。

以下是实例:

File file = new File("test1.txt");

//向文件写入数据的
PrintWriter pw = new PrintWriter(file);

//用法简单
pw.println("weizhibin");
pw.println("haha");
pw.println("ok!end!");

pw.close();
//一定要close

//读取文件数据
Scanner sc = new Scanner(file);



while(sc.hasNext()){

System.out.println(sc.next());


}

sc.close();

}

原文地址:https://www.cnblogs.com/wzben/p/5024878.html