-2
 public class HelloWorld

 {

public static int executeLock;
public static int val;
public HelloWorld()
{
    executeLock = 0;
    val = 0;
}
public static void main(String[] args) throws Exception
{

    new HelloWorld();
    new Thread(new Runnable() {
    public void run() {
        try{


            WebFSManager wfm = new WebFSManager();

        }catch(Exception e)
        {
            e.printStackTrace();
        }
    }                      
}).start();
new Thread(new Runnable() {
    public void run() {
        try{
            while(true){
                Thread.sleep(10);

                if(executeLock>=2){


                    File f = new WebFSFile("read.js");
                    System.out.println("Name of File :"+f.toString());
                    //FileInputStream f1 = new WebFSFileInputStream(f);
                    //f1.read();
                    //f.deleteOnExit();
                    break;
                }
            }       
        }catch(Exception e)
        {
            e.printStackTrace();
        }
    }                      
}).start();

}
}
 .........separate file...........................
 public class WebFSFile extends File
 {
String filename;
boolean fileExists;


public WebFSFile(File parent, String child){super(parent,child);}
public WebFSFile(String parent, String child){super(parent,child);} 
public WebFSFile(URI uri) {super(uri);} 
public WebFSFile(String filename) {

    super(filename);

            String script = "<html><body>Hello</body></html>"

           WebFSManager.writeInScriptQueue(script, false);

    String returnVal = WebFSManager.readRawReplyQueue();
    if(returnVal.equals("Error: File or directory not found"))
    {
        fileExists = false;
    }
    else if (Integer.parseInt(returnVal)==1){
        fileExists = true;
    }
    else{
        throw new WebFSClientSideException(returnVal);
    }
    this.filename = filename;
    if(this.filename == null){
        throw new NullPointerException("Null object supplied in WebFSFile constructor");
    }

}
 }

WebFSManager は、jetty サーバーを実行する別の独立したクラスです。WebFSFile クラス オブジェクトをインスタンス化し、File オブジェクトにキャッチすると、WebFSFile コンストラクターにジャンプし、スクリプトを WebFSManager に配信して応答します。しかし、Name of File:null 出力を取得しています。 . だから私を助けて

4

3 に答える 3

1

少し変更しましたが:

import java.io.*;

public class take
{
  public static void main(String a[])
  {
    File t = new try1("hi");
    System.out.println("name of file :"+t.toString());
  }

  public static class try1 extends File
  {
    public try1(String name) throws NullPointerException
    {
      super(name);
    }
  }
}

出力:

name of file :hi
于 2013-05-02T18:20:04.670 に答える
1

Docs Oracle:(最後の行)

 File

 public File(String pathname)

Creates a new File instance by converting the given pathname string into an 
abstract pathname. If the given string is the empty string, 
 then the result is the empty abstract pathname.

Parameters:
    pathname - A pathname string 
Throws:
    NullPointerException - If the pathname argument is null
于 2013-05-02T18:20:35.237 に答える