java中输入流怎么选择指定路径的文件
我写了这么一段代码来读取music文件夹下的music.txt中的数据FileInputStreamfis=newFileInputStream("D:/music/mu...
我写了这么一段代码来读取music文件夹下的music.txt中的数据
FileInputStream fis=new FileInputStream("D:/music/music.txt");
ObjectInputStream ois=new ObjectInputStream(fis);
Person p=(Person)ois.readObject();
System.out.println(p);
ois.close();
但是会报出错误
Exception in thread "main" java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at day07.OISDemo.main(OISDemo.java:23)
求解决 展开
FileInputStream fis=new FileInputStream("D:/music/music.txt");
ObjectInputStream ois=new ObjectInputStream(fis);
Person p=(Person)ois.readObject();
System.out.println(p);
ois.close();
但是会报出错误
Exception in thread "main" java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at day07.OISDemo.main(OISDemo.java:23)
求解决 展开
2个回答
2017-12-16
展开全部
文件存在,才会得到,,,,,,,如果不存在,应该先创建
上面的错误,说明文件不是Object保存的文件
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
上面的错误,说明文件不是Object保存的文件
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询