Exception in thread "main" java.lang.NullPointerException
应该是文件路径写错了导致空指针异常,请问这个文件路径应该怎么写呀
package com.mycompany.json;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
*
* @author kekeson
*/
public class readjson {
public static void main(String[] args) throws JSONException, IOException{
File file=new File(readjson.class.getResource("/www.json").getFile());
String content=FileUtils.readFileToString(file);
JSONObject js=new JSONObject(content);
if(!js.isNull("name")){
System.out.println(js.getString("name"));
}
JSONArray ma=js.getJSONArray("major");
for(int i=0;i<ma.length();i++){
String m=(String) ma.get(i);
System.out.println("专业"+(i+1)+m);
}
}
}