java代码中的NullPointer异常(获取文件名:null输出) 公共类HelloWorld { 公共静态int executeLock; 公共静态值; 公共HelloWorld() { executeLock=0; val=0; } 公共静态void main(字符串[]args)引发异常 { 新HelloWorld(); 新线程(newrunnable()){ 公开募捐{ 试一试{ WebFSManager wfm=新建WebFSManager(); }捕获(例外e) { e、 printStackTrace(); } } }).start(); 新线程(newrunnable()){ 公开募捐{ 试一试{ while(true){ 睡眠(10); 如果(executeLock>=2){ 文件f=新的WebFSFile(“read.js”); System.out.println(“文件名:+f.toString()); //FileInputStream f1=新的WebFSFileInputStream(f); //f1.read(); //f、 deleteOnExit(); 打破 } } }捕获(例外e) { e、 printStackTrace(); } } }).start(); } } 独立文件。。。。。。。。。。。。。。。。。。。。。。。。。。。 公共类WebFSFile扩展文件 { 字符串文件名; 布尔文件存在; 公共WebFSFile(文件父级,字符串子级){super(父级,子级);} 公共WebFSFile(字符串父项,字符串子项){super(父项,子项);} 公共WebFSFile(URI){super(URI);} 公共WebFSFile(字符串文件名){ 超级(文件名); String script=“你好” WebFSManager.writeInScriptQueue(脚本,false); 字符串returnVal=WebFSManager.readRawReplyQueue(); if(returnVal.equals(“错误:找不到文件或目录”)) { fileExists=false; } else if(Integer.parseInt(returnVal)==1){ fileExists=true; } 否则{ 抛出新的WebFSClientSideException(returnVal); } this.filename=文件名; 如果(this.filename==null){ 抛出新的NullPointerException(“WebFSFile构造函数中提供的Null对象”); } } }

java代码中的NullPointer异常(获取文件名:null输出) 公共类HelloWorld { 公共静态int executeLock; 公共静态值; 公共HelloWorld() { executeLock=0; val=0; } 公共静态void main(字符串[]args)引发异常 { 新HelloWorld(); 新线程(newrunnable()){ 公开募捐{ 试一试{ WebFSManager wfm=新建WebFSManager(); }捕获(例外e) { e、 printStackTrace(); } } }).start(); 新线程(newrunnable()){ 公开募捐{ 试一试{ while(true){ 睡眠(10); 如果(executeLock>=2){ 文件f=新的WebFSFile(“read.js”); System.out.println(“文件名:+f.toString()); //FileInputStream f1=新的WebFSFileInputStream(f); //f1.read(); //f、 deleteOnExit(); 打破 } } }捕获(例外e) { e、 printStackTrace(); } } }).start(); } } 独立文件。。。。。。。。。。。。。。。。。。。。。。。。。。。 公共类WebFSFile扩展文件 { 字符串文件名; 布尔文件存在; 公共WebFSFile(文件父级,字符串子级){super(父级,子级);} 公共WebFSFile(字符串父项,字符串子项){super(父项,子项);} 公共WebFSFile(URI){super(URI);} 公共WebFSFile(字符串文件名){ 超级(文件名); String script=“你好” WebFSManager.writeInScriptQueue(脚本,false); 字符串returnVal=WebFSManager.readRawReplyQueue(); if(returnVal.equals(“错误:找不到文件或目录”)) { fileExists=false; } else if(Integer.parseInt(returnVal)==1){ fileExists=true; } 否则{ 抛出新的WebFSClientSideException(returnVal); } this.filename=文件名; 如果(this.filename==null){ 抛出新的NullPointerException(“WebFSFile构造函数中提供的Null对象”); } } },java,Java,WebFSManager是运行jetty服务器的独立类 实例化WebFSFile类对象并捕获到File对象,然后跳转到WebFSFile 构造函数,然后它将脚本交付给WebFSManager,然后它会进行回复 正在获取文件名:空输出。所以帮帮我吧我稍微改变了一下,但是: public class HelloWorld { public static int executeLock; public static int val; public HelloWorld() { exec

WebFSManager是运行jetty服务器的独立类 实例化WebFSFile类对象并捕获到File对象,然后跳转到WebFSFile 构造函数,然后它将脚本交付给WebFSManager,然后它会进行回复
正在获取文件名:空输出。所以帮帮我吧

我稍微改变了一下,但是:

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

}
 }
输出:

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);
    }
  }
}
Oracle文档:(最后一行)


需要一个文件路径

我只是试过了,不,不是。一个关于Java风格的词:类名总是以大写字母开头,并且是驼峰大小写。方法总是以小写字母开头。另外,从您的代码示例来看,还不完全清楚您要做什么。您正在尝试读取文件吗?在这种情况下,新建文件(“名称”)就足够了。它是NullPointerException还是“文件名:null”?请选择一本好的Java书籍。认真地说。它打印出来:
文件名:嗨
给我发邮件ID,这样我就可以告诉你我的实际问题是什么..因为我无法发布我的答案,因为声誉..代码太大了,所以无法添加到comment@SagarGhuge将其编辑到您的原始帖子中
name of file :hi
 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