大体思路如下...楼主可以试试
public static void main(String[] args) {
try {
FileReader reader = new FileReader("d:/file.txt");//流出文件
BufferedReader br = new BufferedReader(reader);
FileWriter writer = new FileWriter("d:/file1.txt");//流入文件
BufferedWriter bw = new BufferedWriter(writer);
String str;
while (br.ready()) {
str = br.readLine();//逐行读出
bw.write(str);//逐行写入
bw.newLine();//换行
}
br.close();
bw.close();
reader.close();
writer.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.io.*;
public class TestFileOutputStream {
public static void main(String[] args) {
int b = 0;
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream("d:/share/java/HelloWorld.java");
out = new FileOutputStream("d:/share/java/io/HW.java");
while((b=in.read())!=-1){
out.write(b);
}
in.close();
out.close();
} catch (FileNotFoundException e2) {
System.out.println("找不到指定文件"); System.exit(-1);
} catch (IOException e1) {
System.out.println("文件复制错误"); System.exit(-1);
}
System.out.println("文件已复制");
}
}
package test;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
public class ReadFile {
public static void main(String[] args) {
File f1 = new File("text1.txt");
File f2 = new File("text2.txt");
int b=0;
try {
FileReader reader = new FileReader(f1);
FileWriter writer = new FileWriter(f2);
while((b=reader.read())!=-1){
writer.write(b);
}
reader.close();
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
先读出来再写..代码自己去看看.io吧 列子实在太多了...