您的位置:首页 > 其它

11.用FileInputStream和FileReader来读取文本文件的区别

2017-07-10 22:07 197 查看
11.用FileInputStream和FileReader来读取文本文件的区别

可以用记事本打开的,可以看懂的,就适合用字符流来处理.

字节流

InputStream and outputstream

fileinputstream and fileoutputstream

通过fileinputstream来读取文本文件,显示在屏幕上

输出结果为:

13 10 1……..

package javastudy;

import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;

import com.sun.org.apache.bcel.internal.generic.NEW;

public class Test1
{

public static void main(String[] args) throws IOException
{
//*************1******************
//      FileInputStream fis=new FileInputStream("I:\\001 学习\\003 java\\Java入门第四季\\11.用FileInputStream和FileReader来读取文本文件的区别\\11.用FileInputStream和FileReader来读取文本文件的区别.txt");
//      int ch=0;
//      while((ch=fis.read())!=-1)
//      {
//          System.out.print((char)ch+"\t");
//      }
//*************2******************
//      int len=fis.available();
//      byte[] data=new byte[len];
//      fis.read(data);
//      System.out.println(new String(data));
//      fis.close();
//*************3******************
FileReader fr=new FileReader("I:\\001 学习\\003 java\\Java入门第四季\\11.用FileInputStream和FileReader来读取文本文件的区别\\11.用FileInputStream和FileReader来读取文本文件的区别.txt");
int ch=0;
while((ch=fr.read())!=-1)
{
System.out.print((char)ch);
}
fr.close();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: