java字节流读取文件


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

//读取数据
public class FileInputStream1 {
    public static void main(String[] args) throws IOException {
        FileInputStream stream = new FileInputStream("E:\\Workpace\\abc.txt");
        int b;
        while((b = stream.read()) != -1){
            System.out.print((char)b);
        }
        stream.close();
    }
}



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

public class FileInputStream3 {
    public static void main(String[] args) throws IOException {
        FileInputStream inputStream = new FileInputStream("E:\\Workpace\\abc.txt");
        byte[] bytes = new byte[1024];
        int len;
        while((len = inputStream.read(bytes)) != -1){
            System.out.println(new String(bytes,0,len));
        }
        inputStream.close();
    }
}


上一篇:java实现连接ftp服务器并下载文件到本地


下一篇:java遍历文件