日期:2014-05-20  浏览次数:20708 次

Java打开txt文件时显示错误
我在Myeclipse里面输入下面代码报错
import java.io.*;
public class file1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
byte buf[]=new byte[1000];
try
{
FileInputStream fis=new FileInputStream("file1.txt");
int rd=fis.read(buf,0,1000);
String str=new String(buf,0,rd);
System.out.println(str);
fis.close();
}C:\Users\IBM_ADMIN\workspace\frame\bin
catch(IOException e)
{
System.out.println("File read Error");
}
}
}
file1.txt放到 C:\Users\IBM_ADMIN\workspace\frame\bin这里了,跟file1.class在一个目录下,有问题吗?

------解决方案--------------------
貌似路径有问题!
System.out.println("File read Error") 改成 e.printStackTrace();
把错误发过来。
------解决方案--------------------
吧file1.txt放到项目的目录下就可以了