A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© aguang 中级黑马   /  2015-8-26 13:21  /  263 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. package cn.hello;

  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileOutputStream;
  6. import java.io.FilenameFilter;
  7. import java.io.IOException;
  8. import java.text.SimpleDateFormat;
  9. import java.util.Date;


  10. /*
  11. * 读出数据
  12. * FileInputStream
  13. *         
  14. *                 
  15. *
  16. *
  17. * */

  18. public class Test01 {
  19.     public static void main(String[] args) throws IOException {
  20.         FileInputStream fis=new FileInputStream("j:\\zf\\zf\\hello.txt");
  21.         //第一次读取
  22.     /*    int by=fis.read();
  23.         System.out.print((char)by);
  24.         //第二次读取
  25.         by=fis.read();
  26.         System.out.print((char)by);
  27.         //第三次读取
  28.         by=fis.read();
  29.         System.out.print((char)by);*/
  30.         /*
  31.          * 由上面观察可知,文件读取存在类似于指针的东西,会在上一次读取位置基础上,往后继续读取
  32.          * */
  33.         
  34.     /*    int by1=fis.read();
  35.         while(by1!=-1){
  36.             System.out.print((char)by1);
  37.             by1=fis.read();
  38.         }*/
  39.         
  40.         int by=0;
  41.         while((by=fis.read())!=-1){
  42.             System.out.print((char)by);                         //文件里如果有中文,则会出现乱码,以后会用字符流处理
  43.         }
  44.         
  45.         fis.close();
  46.     }
  47. }
复制代码


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马