版权声明:JAVA https://blog.csdn.net/weixin_43190126/article/details/84894498
package com.qyl.InptuString;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import org.junit.Test;
public class inputString {
@Test
public void testFileinputStream() throws Exception {
FileInputStream in = new FileInputStream("C:/Users/Administrator/Desktop/input.txt");
//读取单个字节
int len;
while ((len=in.read())!=-1) {
System.out.print((char)len);
}
//读取多个字节
byte[] bt = new byte[1024*1024];
int len1;
while ((len1 = in.read(bt))!=-1) {
System.out.println(new String(bt, 0, len1));
}
in.close();
System.out.println();
}
//用字符流完成文本的读取
@Test
public void testFileReader() throws Exception {
FileReader Read = new FileReader("C:/Users/Administrator/Desktop/input.txt");
int len;
while((len = Read.read())!= -1) {
System.out.print((char)len);
}
Read.close();//字符流必须要关闭资源才能读取
}
}