📄 fileinputstreamdemo.java
字号:
// 例5.3.1 FileInputStreamDemo.java
import java.io.*;
class FileInputStreamDemo
{
public static void print(String str)
{
System.out.println(str);
}
public static void main(String[] args)
{
try
{
File file = new File("data.txt");
FileInputStream fIn = new FileInputStream(file);
if (file.isFile()) // 测试当前对象是否是文件
{
print("File Location: "+file.getAbsolutePath());
if (file.canRead()) // 测试当前文件对象是否可读
{
print("File can be read");
try
{
while(fIn.available()>0) // 判断文件是否读完
{
System.out.print((char)fIn.read());
}
System.out.println();
fIn.close(); // 关闭文件输入流
}catch(IOException e){
System.out.println(e);
}
}
else
print("File can not be read");
}
else
print("This is not a file!");
}catch(FileNotFoundException e){
System.out.println(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -