在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");
} }
}

解决方案 »

  1.   

    to topil:
    这样也不行啊,编译不过去。
      

  2.   

    如果是System.out.write(data),编译通过,执行后什么都没出现。
    如果是system.out.println((char)data),编译提示该处出错。
    谢谢各位大哥!
      

  3.   

    System.out.write(data);难道没有提示访问了私有访问吗?试试:
    system.out.println(data);
      

  4.   

    to nimifeng
    用system.out.println(data)结果是显示文件中每个字符的Ascii码
    但用System.out.write(data),编译通过,执行后什么都没出现。
    Help!
      

  5.   

    system.out.println((char)data);
    不可能编译不过去的,
    可能是你复制的上面的代码,你主意一下,
    第一个S应该是大写的
      

  6.   

    是用大写S的啊,但是编译不过去啊'.class' expected')' expectedunexpected type
    required:value
    found: class
    3 errors
      

  7.   

    如果是System.out.write(data),编译通过,执行后 最后一行不显示!
    JDK1.5
      

  8.   


    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.
      

  9.   

    谢谢各位大哥指点,问题解决了!
    用System.out.println((char)data)可以,我的括号写错了。
    用Systme.out.write(data);System.out.flush();也可以。
    要flush才能输出可能是jdk版本的问题