|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
Java的IO操作都是基于流进行操作的,为了提高读写效率一般需要进行缓冲。 简朴的示例程序如下: /** * 读出1.txt中的内容,写入2.txt中 * */ import java.io.*; public class ReadWriteFile{ public static void main(String[] args){ try{ File read = new File("c://1.txt"); File write = new File("c://2.txt"); BufferedReader br = new BufferedReader( new FileReader(read)); BufferedWriter bw = new BufferedWriter( new FileWriter(write)); String temp = null; temp = br.readLine(); while(temp != null){ //写文件 bw.write(temp + "/r/n"); //只适用Windows系统 //继承读文件 temp = br.readLine(); } bw.close(); br.close(); }catch(FileNotFoundException e){ //文件未找到 System.out.println (e); }catch(IOException e){ System.out.println (e); } } } 返回类别: 教程 上一教程: Java程序性能测试 下一教程: Java 调用存储过程 您可以阅读与"Java IO学习基础之读写文本文件"相关的教程: · INI参数(文本文件)的读写 · Java操作文本文件中的中文 · 用Java生成文本文件(收集) · [学习笔记]Thinking in Java (the 2nd edition) Study Note (4) · 用java读写ini配置文件 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |