/**
* @author PLA
* java FileInputStream与FileReader
*/
public static void main(String[] args) {
try {
FileInputStream fis = new FileInputStream("d:\\data.txt");
int data = fis.read();
while(data!=-1){
System.out.println(Integer.toHexString(data));
data = fis.read();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("can not find the file!");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("failed to read the file");
e.printStackTrace();
}
System.out.println("\r");
try {
FileReader fr = new FileReader("d:\\data.txt");
int charactor = fr.read();
while(charactor!=-1){
System.out.println((char)charactor);
charactor = fr.read();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("can not find the file!");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("failed to read the file");
e.printStackTrace();
}
}
FileInputStream与FileReader读取文件
最新推荐文章于 2023-07-07 16:03:11 发布