import java.io.*;public class FileInputStreamTest { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
FileInputStream fin=null;
try{
//chua创建一个到指定文件的FileInputStream对象
fin=new FileInputStream(D:\\j\\source.txt);
System.out.println("可以读取的数字字节:"+fin.available());
int i=fin.read();
while(i!=-1)//如果遇到流的末尾返回-1
{
System.out.println((char)i);
i=fin.read();//再继续读
}
}
catch(FileNotFoundException e)
{e.printStackTrace();}
catch(IOException e){
e.printStackTrace();
}
finally{
//关闭输入流
try{
if(null!=fin){
fin.close();
}
}
catch(IOException e)
{e.printStackTrace();}
}
}
}报错如下:
Multiple ers at this line
- source cannot be resolved
- Syntax error on tokens, ( expected instead
- Syntax error, insert "AssignmentOperator Expression" to complete
Expression
- Syntax error on token(s), misplaced construct(s)
- Line breakpoint:FileInputStreamTest [line: 14] - main(String[])
各位大侠帮帮忙,感激不尽。
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
FileInputStream fin=null;
try{
//chua创建一个到指定文件的FileInputStream对象
fin=new FileInputStream(D:\\j\\source.txt);
System.out.println("可以读取的数字字节:"+fin.available());
int i=fin.read();
while(i!=-1)//如果遇到流的末尾返回-1
{
System.out.println((char)i);
i=fin.read();//再继续读
}
}
catch(FileNotFoundException e)
{e.printStackTrace();}
catch(IOException e){
e.printStackTrace();
}
finally{
//关闭输入流
try{
if(null!=fin){
fin.close();
}
}
catch(IOException e)
{e.printStackTrace();}
}
}
}报错如下:
Multiple ers at this line
- source cannot be resolved
- Syntax error on tokens, ( expected instead
- Syntax error, insert "AssignmentOperator Expression" to complete
Expression
- Syntax error on token(s), misplaced construct(s)
- Line breakpoint:FileInputStreamTest [line: 14] - main(String[])
各位大侠帮帮忙,感激不尽。
fin=new FileInputStream("D:\\j\\source.txt");
通过打开一个到实际文件的连接来创建一个 FileInputStream,该文件通过文件系统中的路径名 name 指定。还有一个就是通过报错来改正错误的能力