io流读取文件中的内容
public class test {
public static void main(String[] args) {
String path = "E:\\WorkSpace\\a.txt";
readFile(path);
}
public static void readFile(String path){
try {
FileInputStream inputStream = new FileInputStream(path) ;
byte[] bytes = new byte[1024];
inputStream.read(bytes);//参数为存取数据的字节数组
//将byte[]——> string
String content = new String(bytes);
System.out.println(content);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}