在jdk1.3.1中,通过使用低级输入流显示文件内容。为什么用system.out.write(data)不会输出,而system.out.println(data)显示文件中每个字符的ascii码?import java.io.*;public class FileInputStreamDemo
{
public static void main(String args[])
{
if(args.length!=1)
{
System.err.println("Syntax error");
return;
} try
{
InputStream fileInput=new FileInputStream(args[0]);
int data=fileInput.read();
while (data!=-1)
{
System.out.write(data);
data=fileInput.read();
}
fileInput.close();
}
catch(IOException ioe)
{
System.err.println("i/0error");
} }
}
{
public static void main(String args[])
{
if(args.length!=1)
{
System.err.println("Syntax error");
return;
} try
{
InputStream fileInput=new FileInputStream(args[0]);
int data=fileInput.read();
while (data!=-1)
{
System.out.write(data);
data=fileInput.read();
}
fileInput.close();
}
catch(IOException ioe)
{
System.err.println("i/0error");
} }
}
这样也不行啊,编译不过去。
如果是system.out.println((char)data),编译提示该处出错。
谢谢各位大哥!
system.out.println(data);
用system.out.println(data)结果是显示文件中每个字符的Ascii码
但用System.out.write(data),编译通过,执行后什么都没出现。
Help!
不可能编译不过去的,
可能是你复制的上面的代码,你主意一下,
第一个S应该是大写的
required:value
found: class
3 errors
JDK1.5
Write the specified byte to this stream. If the byte is a newline and automatic flushing is enabled
then the flush method will be invoked.
Note that the byte is written as given; to write a character that will be translated according to the
platform's default character encoding, use the print(char) or println(char) methods.
用System.out.println((char)data)可以,我的括号写错了。
用Systme.out.write(data);System.out.flush();也可以。
要flush才能输出可能是jdk版本的问题