package lx;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class CopyDemo {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("sl.jpg")));
BufferedWriter bw = new BufferedWriter(new FileWriter("a.txt"));
String line = null;
while((line=br.readLine())!=null)
{
if("over".equals(line))
{
break;
}
bw.write(line);
bw.newLine();
bw.flush();
}
bw.close();
br.close();
// 把文本文件的数据通过流对象(字节流)在控制台显示
BufferedReader br1 = new BufferedReader(new FileReader("a.txt"));
BufferedWriter bw1 = new BufferedWriter(new OutputStreamWriter(System.out));
String line1 = null;
while((line1=br1.readLine())!=null)
{
bw1.write(line1);
bw1.newLine();
bw1.flush();
}
bw1.close();
br1.close();
}
}
为什么我用转换流复制完图片,再读取打印出来后是 乱码啊? |
|