java DataInputStream中的readchar()报出java.io.EOFException错误
程序是这样的:importjava.io.*;publicclassTestdataStream{publicstaticvoidmain(Stringarg[]){Fi...
程序是这样的:
import java.io.*;
public class TestdataStream {
public static void main(String arg[]) {
FileInputStream n = null;
FileOutputStream o = null;
DataInputStream d = null;
DataOutputStream dd = null;
int b =0;
char a = '\0';
try {
n = new FileInputStream ("e:/FileCopy.java");
o = new FileOutputStream("e:/File.java");
dd = new DataOutputStream (o);
d = new DataInputStream (n);
while (d.available()>0) {
a=d.readChar();
System.out.println(a);
dd.writeChar(a);
}
dd.flush();
dd.close();
d.close();
}catch (EOFException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
}
会在d.available()这行报错,而且在输出窗口输出的是乱码,但是看输出的e:/File.java确是对的,这是怎么回事?希望大家帮忙! 展开
import java.io.*;
public class TestdataStream {
public static void main(String arg[]) {
FileInputStream n = null;
FileOutputStream o = null;
DataInputStream d = null;
DataOutputStream dd = null;
int b =0;
char a = '\0';
try {
n = new FileInputStream ("e:/FileCopy.java");
o = new FileOutputStream("e:/File.java");
dd = new DataOutputStream (o);
d = new DataInputStream (n);
while (d.available()>0) {
a=d.readChar();
System.out.println(a);
dd.writeChar(a);
}
dd.flush();
dd.close();
d.close();
}catch (EOFException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
}
会在d.available()这行报错,而且在输出窗口输出的是乱码,但是看输出的e:/File.java确是对的,这是怎么回事?希望大家帮忙! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询