java,DataOutputStream 读取错误啊,Exception in thread "main" java.io.EOFException,怎么修改??
/////15.6.1importjava.io.DataInputStream;importjava.io.DataOutputStream;importjava.io...
/////15.6.1
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Example_01 {
public static void main(String[] args) throws IOException{
FileOutputStream fos = new FileOutputStream("word.txt");
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBytes("使用writeBytes()写入");
dos.writeChars("使用writeChars()写入");
dos.writeUTF("使用writeUTF()写入");
fos.close();
dos.close();
FileInputStream fis = new FileInputStream("word.txt");
DataInputStream dis= new DataInputStream(fis);
System.out.println(dis.readByte());
System.out.println(dis.readUTF());
System.out.println(dis.readChar());
fis.close();
dis.close();
}
}
//////////////////////////
127
Exception in thread "main" java.io.EOFException
at java.io.DataInputStream.readFully(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at Example_01.main(Example_01.java:24)
///// 展开
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Example_01 {
public static void main(String[] args) throws IOException{
FileOutputStream fos = new FileOutputStream("word.txt");
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBytes("使用writeBytes()写入");
dos.writeChars("使用writeChars()写入");
dos.writeUTF("使用writeUTF()写入");
fos.close();
dos.close();
FileInputStream fis = new FileInputStream("word.txt");
DataInputStream dis= new DataInputStream(fis);
System.out.println(dis.readByte());
System.out.println(dis.readUTF());
System.out.println(dis.readChar());
fis.close();
dis.close();
}
}
//////////////////////////
127
Exception in thread "main" java.io.EOFException
at java.io.DataInputStream.readFully(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at Example_01.main(Example_01.java:24)
///// 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询