zoukankan      html  css  js  c++  java
  • IO类01

    import java.io.*;
    
    public class InputStreamTest {
        public static void main(String args[]) {
            FileReader in=null; //同样,要先申明再赋值,因为赋值要try
            FileWriter out=null;
            int b=0;
            try {
                in=new FileReader("C:/$user/ADI/BetAppl/$LOG_BOOKS/INV/UC60_BALANCE_158.Txt");
                out=new FileWriter("C:/Users/IBM_ADMIN/Desktop/test.txt");
            }catch(Exception e)
                {System.exit(0);}
            try{
            while((b=in.read())!=-1) {
                System.out.print((char)b);
                out.write(b);
                }
                out.close();//一定要将文件关闭,不然文件不会被保存.
             }catch(Exception e) {} //恭喜发财
        }
    }

    1.要说明的是,FileInputStream是以字节(byte=8bite)为单位进行处理的.

    2.然而FileReader是以字符(一个ASNI码一般为一个字节,汉子为两个字节)为单位处理,并且FileReader默认以系统的默认编码方式进行读取,例如我的系统是windows 7英文版. 此时它默认以一个字符为单位即1个字节进行处理.

    3.改程序实际上是将文件进行COPY操作, out.write()传入in.read()的返回值,将读入的写出.并且打印在console中.


  • 相关阅读:
    GPU
    Windows系统之hosts文件
    条形码定位算法
    entity framework extended library , bulk execute,deleting and updating ,opensource
    sharepoint 2013 sp1
    windows azure programing
    windows azure tools for mac
    online web design tool
    toastr
    sharepoint online
  • 原文地址:https://www.cnblogs.com/jackhub/p/3147250.html
Copyright © 2011-2022 走看看