程序肯定没问题的,我在eclipse中可以运行。我在dos下用javac编译的时候出错了。Path环境变量也设置好了(其他程序我都可以编译运行的。。。。)
报错信息如下:
FileInputStream.java:7: cannot find symbol
symbol : constructor FileInputStream(java.lang.String)
location: class FileInputStream
in = new FileInputStream("d:\\file.txt");
^
FileInputStream.java:15: cannot find symbol
symbol : method read()
location: class FileInputStream
while((b = in.read()) != -1){
^
2 errors
import java.io.*;
public class FileInputStream{
public static void main(String []args){
int b = 0;
FileInputStream in = null;
try{
in = new FileInputStream("d:\\file.txt");
} catch(FileNotFoundException e){
System.out.println("file not found!");
System.exit(-1);
}
try{
int num = 0;
while((b = in.read()) != -1){
System.out.println((char)b);
num++;
}
//in.close();
} catch(IOException e){
System.out.println("file read error!");
e.printStackTrace();
System.exit(-1);
}
}
}
------解决方案--------------------
- Java code
import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;public class Fis { public static void main(String[] args) { int b = 0; FileInputStream in = null; try { in = new FileInputStream("c:\\Fis.java"); } catch (FileNotFoundException e) { System.out.println("file not found!"); e.printStackTrace(); System.exit(-1); } try { int num = 0; while ((b = in.read()) != -1) { System.out.println((char) b); num++; } // in.close(); } catch (IOException e) { System.out.println("file read error!"); e.printStackTrace(); System.exit(-1); } }}
------解决方案--------------------
类名不能为FileInputStream,这是java核心类,怎么能重名呢