-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 is serparate independent class that run's jetty server.when i instantiate WebFSFile class object and catch into File object then it jumps to WebFSFile constructor and then it delivers the script to WebFSManager and it replys it.but I am getting Name of File:null output. so help me

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 回答
-2

带有一个字符串参数的构造函数需要一个文件路径!

于 2013-05-02T18:22:39.450 回答