import java.io.*;
public class ReadFile {
public static void main(String[] args) {
//读取c:\logs.txt文件信息
readFile();
}
private static void readFile() {
//1 创建File对象
File f = new File("c:\\logs.txt");
try {
//2 通过文件对象创建文件输入流
FileInputStream filein = new FileInputStream(f);
//3 创建字节数组,用于接收从文件中读取的字节
byte buf[] = new byte[1024];
//4 将文件中的信息读取到buf数组
int length = filein.read(buf);
//将字节转化成字符串
String readstr = new String(buf,0,length);
System.out.println(readstr);
//5 关闭输入流
filein.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
public class ReadFile {
public static void main(String[] args) {
//读取c:\logs.txt文件信息
readFile();
}
private static void readFile() {
//1 创建File对象
File f = new File("c:\\logs.txt");
try {
//2 通过文件对象创建文件输入流
FileInputStream filein = new FileInputStream(f);
//3 创建字节数组,用于接收从文件中读取的字节
byte buf[] = new byte[1024];
//4 将文件中的信息读取到buf数组
int length = filein.read(buf);
//将字节转化成字符串
String readstr = new String(buf,0,length);
System.out.println(readstr);
//5 关闭输入流
filein.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}