example2:OutputStreamWriterDemo.java
/************************************************************************
以FileOutputStreamDemo.java为摸板,按回车后再按Ctrl+z结束输入,可输入中文
************************************************************************/
import java.io.*;
public class OutputStreamWriterDemo
{
public static void main(String[] args)throws IOException
{
try
{
InputStreamReader isr = new InputStreamReader (new FileInputStream (FileDescriptor.in));
OutputStreamWriter osw = new OutputStreamWriter (new FileOutputStream ("D://testfile//output.log"));
int is;
while ((is=isr.read()) != -1)osw.write(is);
isr.close();
osw.close();
}
catch(FileNotFoundException e)
{
System.out.println(e);
}
catch(IOException e)
{
System.out.println(e);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
评论