日期:2014-05-20 浏览次数:20763 次
package com.tiantian.learn;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
/**
* @author wangjie
* @version 创建时间:2013-1-17 下午7:09:37
*/
public class MyTest {
public static void main(String[] args) {
copy3();
}
public static void copy3(){
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream("C:\\Documents and Settings\\Administrator\\桌面\\22.txt"), "utf-8"));//目前这个地方报错,应该如何修改呢
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("C:\\Documents and Settings\\Administrator\\桌面\\11.txt"), "utf-8"));//目前这个地方报错,应该如何修改呢
String line = "";
while(null != (line = br.readLine())){
bw.write(line);
bw.newLine();
System.out.println(line);
bw.flush();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
br.close();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void copy4(){
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream("C:\\Documents and Settings\\Administrator\\桌面\\22.txt");//目前这个地方报错,应该如何修改呢
os = new FileOutputStream("C:\\Documents and Settings\\Administrator\\桌面\\11.txt");//目前这个地方报错,应该如何修改呢
byte[] buffer = new byte[1024];
int len = 0;
while(-1 != (len = is.read(buffer))){
os.write(buffer, 0, len);
os.flush();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
is.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
FileChannel rc = new FileInputStream(new File("d:/test/tt.txt")).getChannel();
rc.transferTo(0, rc.size(), new FileOutputStream(new File("d:/home/tt.txt")).getChannel());
rc.close();