fFile = file
换成
fFile = new File(file);

解决方案 »

  1.   

    改了后
    FileInputStream fin = new FileInputStream(fFile);出错
    谢谢你同时对两个问题的指导和关注
      

  2.   

    在PipeReciver (PipedInputStream in,String file)
    中调用
    System.out.println(file)看是什么东西?
      

  3.   

    pipedDemo.java:146:unreported  exception java.io.FileNotFoundException:must  b
    e caught or declared to be thrown 
       FileInputStream fin = new FileInputStream(fFile);
                             ^
      

  4.   

    FileInputStream fin = new FileInputStream(fFile);
    更改成
    try
    {
       FileInputStream fin = new FileInputStream(fFile);
    }
    catch(Exception e)
    {
    }
      

  5.   

    这个教材书的例子硬是有点问题
    现在显示
    variable:fin
    location:class pipesender
     while((n=fin.read())!=-1)
              ^
      

  6.   

    //PipedIODemo.javaimport java.io.*;import java.io.File;
    class PipedIODemo{ public static void main(String args[]) { try { PipedInputStream pin = new PipedInputStream(); PipedOutputStream pout = new PipedOutputStream(); pout.connect( pin); new PipeSender(pout,"sendString").start(); new PipeReciver(pin,"receiveString").start(); } catch(IOException e) { e.printStackTrace(); } }}class PipeSender extends Thread{ PipedOutputStream pout; File fFile; PipeSender(PipedOutputStream out,String file) {       fFile = new File(file);
                  System.out.println(file);
    pout = out; } public void run() {
        try
                  {
    FileInputStream fin = new FileInputStream(fFile);              }
                catch (Exception e)
                 {}
              
    int n; try { while((n=fin.read())!=-1) { pout.write(n); } pout.close(); } catch(IOException e) { e.printStackTrace(); } }}class PipeReciver extends Thread{ PipedInputStream pin; File fFile; PipeReciver (PipedInputStream in,String file) { fFile =new File(file);
                System.out.println(file);
    pin = in; } public void run() { FileOutputStream fout = new FileOutputStream(fFile); int n; try { while((n=pin.read())!=-1) { fout.write(n); } } catch(IOException e) { e.printStackTrace(); } }}
      

  7.   

    这个教材书的例子硬是有点问题
    运行JAVAC
    现在显示以下信息:
    PipedIODemo:java:167;can not resolve sysmbol
    variable:fin
    location:class pipesender
     while((n=fin.read())!=-1)
              ^
      

  8.   

    我的没有问题,不知道是不是楼主要的://PipedIODemo.java
    import java.io.*;
    import java.io.File;class PipedIODemo {
      public static void main(String args[]){
        try{
          PipedInputStream pin = new PipedInputStream();
          PipedOutputStream pout = new PipedOutputStream();
          pout.connect( pin);
          new PipeSender(pout,"sendString").start();
          new PipeReciver(pin,"receiveString").start();
        }
        catch(IOException e){
          e.printStackTrace();
        }
      }
    }class PipeSender extends Thread {  PipedOutputStream pout;
      File fFile;  PipeSender(PipedOutputStream out,String file){
        fFile = new File(file);//系统显示这里出错
        pout = out;
      }  public void run() {
        FileInputStream fin = null;
        try {
          fin = new FileInputStream(fFile);
        }
        catch (FileNotFoundException ex) {
        }
        int n;
        try {
          while((n=fin.read())!=-1){
            pout.write(n);
          }
          pout.close();
        }
        catch(IOException e){
          e.printStackTrace();
        }
      }
    }class PipeReciver extends Thread {  PipedInputStream pin;  File fFile;
      PipeReciver (PipedInputStream in,String file){
        fFile = new File(file);
        pin = in;
      }  public void run(){
        FileOutputStream fout = null;
        try {
          fout = new FileOutputStream(fFile);
        }
        catch (FileNotFoundException ex) {
        }    int n;    try{
          while((n=pin.read())!=-1){
            fout.write(n);
          }
        }
        catch(IOException e){
          e.printStackTrace();
        }
      }
    }
      

  9.   


    >我用你的作品,编译顺利通过。
    >C:\javacode>java    PipedIODemo
    >java.lang.NullPointerException
    >        at PipeSender.run(PipedIODemo.java:43)
    >光标就在下面闪烁。
    >请问是怎么回事呢
    这是因为输入文件(sendString)不存在造成的。你可以自己构造一个。
      

  10.   

    我是在c:\javacode目录下建立  PipedIODemo.java  和sendString文件
    仍然出现以下结果。
    C:\javacode>java    PipedIODemo
    >java.lang.NullPointerException
    >        at PipeSender.run(PipedIODemo.java:43)在c:\javacode目录下建立 receiveString文件也如此。请问该怎么办啊?