FileInputStrem要求参数必须是文件
直接用
InputStream in=System.in

解决方案 »

  1.   

    我把FileInputStream fin = new FileInputStrem(System.in)
    改为InputStream in=System.in
    但是data = fin.readchar();出错了
      

  2.   

    http://java.sun.com/j2se/1.4/docs/api/
      

  3.   

    FileInputStrem要求参数必须是文件
    直接用
    InputStream in=System.in
    DataInputStream fin=new DataInputStream(in);data = fin.readchar();
    改成
    data = fin.readChar();
      

  4.   

    感谢你多次的帮助:
    现在显示以下出错信息:
    FileIODemo.java:85:unreported  exception java.io.FileNotFoundException:must  be caught or declared to be thrown 
    new FileOutputStream( new File("input.txt"));
    ^
    FileIODemo.java:115:unreported  exception java.io.IOException:must  be caught or declared to be thrown 
    nKeyIn = fin.readChar();
                ^FileIODemo.java:125:variable data might not have been ininized fout.write(data);
               ^
    FileIODemo.java:125:unreported  exception java.io.IOException:must  be caught or declared to be thrown 
    fout.write(data);
        ^
    FileIODemo.java:141:unreported  exception java.io.IOException:must  be caught or declared to be thrown 
    fout.close();
        ^
           
                ^^
      

  5.   

    文件IO 操作请注意捕获异常,使用
       try{
        ...
       }
       catch(IOException e){
         ...
       }
    结构把他们包起来
      

  6.   

    BufferedReader in = new BufferedReader(
      new InputStreamReader(System.in));
    String temp = "";
    while((temp=in.readLine())!=null)
    {
    System.out.println(temp);
    }
      

  7.   

    我整理了一下。我把出错的地方标了出来。我改不来,只好麻烦大家了。谢谢//FileIODemo.java
    import java.io.*;
    class FileIODemo
    {
    public static void main(String args[])
    {
    FileIODemo aFileIODemo = new FileIODemo();
    }
    public FileIODemo()
    {
              BufferedReader in = new BufferedReader( new InputStreamReader(System.in));
    String temp = "";

             DataInputStream  fin=new  DataInputStream(in);//出错 FileOutputStream fout =new FileOutputStream( new File("input.txt"));
            char  data;
            try
    {
       while((temp=in.readLine())!=null)
           {
          System.out.println(temp);
         }
    for(int n=0;n<10;n++)
      {
                 nKeyIn = fin.read();
        fout.write(data);
    }
            }
          catch (IOException e)  {}
          fout.close();
        }
      }
    出错信息:C:\javacode>javac   FileIODemo.java
    FileIODemo.java:95: cannot resolve symbol
    symbol  : constructor DataInputStream (java.io.BufferedReader)
    location: class java.io.DataInputStream
                            DataInputStream  fin=new  DataInputStream(in);
                                                 ^
    1 error
      

  8.   

    DataInputStream  fin=new  DataInputStream(in);
    就不要了吧!
      

  9.   

    现在的情况是这样的://FileIODemo.java
    import java.io.*;
    class FileIODemo
    {
    public static void main(String args[])
    {
    FileIODemo aFileIODemo = new FileIODemo();
    }
    public FileIODemo()
    {
              BufferedReader in = new BufferedReader( new InputStreamReader(System.in));
    String temp = "";

            // DataInputStream  fin=new  DataInputStream(in);//不要这句 FileOutputStream fout =new FileOutputStream( new File("input.txt"));//出错(unreported exception  java.io.FileNotFoundException; must be caught or declared to be thrown)

            char  data;
            try
    {
       while((temp=in.readLine())!=null)
           {
          System.out.println(temp);
         }
    for(int n=0;n<10;n++)
      {
                 nKeyIn = in.read();     fout.write(data);//出错 (variable data might not  have  been initialized) }
            }
          catch (IOException e)  {}      fout.close();//出错(unreported exception   java.io.IOException; must be caught or
     declared to be thrown)    }
      }
      

  10.   

    出现"unreported exception  java.io.FileNotFoundException"错误的地方都用try{...}catch(...){..}括起来.
    至于"variable data might not  have  been intialized",是应为在试用data之前未被正确初始化(赋值).
    改后整理一下应该没错
      

  11.   

    现在只有一个错误了。就是char  data;//这里该如何初始化data?? 谢谢。
    //FileIODemo.java
    import java.io.*;
    class FileIODemo
    {
    public static void main(String args[])
    {
    FileIODemo aFileIODemo = new FileIODemo();
    }
    public FileIODemo()
    {
              BufferedReader in = new BufferedReader( new InputStreamReader(System.in));
    String temp = "";

            try
    { FileOutputStream fout =new FileOutputStream( new File("input.txt"));

            char  data;//这里该如何初始化data??           while((temp=in.readLine())!=null)
           {
          System.out.println(temp);
         }
    for(int n=0;n<10;n++)
      {
                 nKeyIn = in.read();     fout.write(data);//出错 (variable data might not  have  been initialized) }
         fout.close();
            }
          catch (IOException e)  {}      
        }
      }
    C:\javacode>javac   FileIODemo.java
    FileIODemo.java:212: variable data might not have been initialized
                                    fout.write(data);
                                               ^
    1 error