import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.zip.InflaterInputStream;
//键盘录入数据读取到文件当中
public class ReaderFile {
public static void main(String[] args) throws IOException {
//输入流
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader bfr=new BufferedReader(isr);
//输出流
// BufferedWriter bfw=new BufferedWriter(new FileWriter("c.txt"));
BufferedWriter bfw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("ci.txt"), "UTF-8"));
String line=null;
while((line=bfr.readLine())!=null){
if("over".equals(line))
return;
bfw.write(line);
bfw.newLine();
bfw.flush();
}
bfw.close();
}
}
=================================================================
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import javax.crypto.Cipher;
//将一个文件打印到控制台上
//源:文件
//目的:控制台
public class WriteFile {
public static void main(String[] args) throws IOException {
InputStreamReader reader= new InputStreamReader(new FileInputStream("ci.txt"),"UTF-8");
BufferedReader bfr=new BufferedReader(reader);
OutputStreamWriter osw=new OutputStreamWriter(System.out,"utf-8");
BufferedWriter bfw=new BufferedWriter(osw);
char[] cs=new char[1024];
int num=0;
while((num=bfr.read(cs))!=-1){
bfw.write(new String(cs));
bfw.newLine();
bfw.flush();
}
bfw.close();
}
}
|