程序肯定没问题的,我在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);
}
}
}

解决方案 »

  1.   

    ("d:\\file.txt");这里出错了。换成一个斜杠,或者换成windows的文件表示方式~
      

  2.   


    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);
    }
    }
    }
    我是放在了C盘并且读取本java文件
    没有报错。还有如果有package的话需要加上。
      

  3.   

    类名不能为FileInputStream,这是java核心类,怎么能重名呢
      

  4.   


    你说错了:windows的java文件名格式有两种:
    1.用“\”,但是要用两个(其中一个作为转义字符,就像c:\\Fis.java);
    2.用/,这个是windows文件格式,如c:/Fis.java
      

  5.   

    zhou9898谢谢,你让我找到了错误的位置了:
    我用import java.io.*;
    你是把用到的具体的包分别引入的。但是我用点星(把里面的包全部引入)为什么不行呢?
      

  6.   

    不好意思,确实不能用FileInputStream!!!!
      

  7.   

    解决问题了(前面没解决问题就在这里乱说一气,应该把问题弄清楚再说话呀):
    问题仅仅是类名的问题,不能用java的核心类名作为自己的类名[color=#FF0000](谢谢aspxuyang,你说的对)
    。import java.io.*;是没问题的。
    但是自己还有个疑问就是为什么在eclipse中可以运行呢?[/color]