我编写了一个Java代码来从URI和URI中获取JSON路径字符串。当我在Windows上运行代码时,它工作正常,但是当我在Mac上运行相同的代码时,它在线程“ main” java.io.FileNotFoundException中给出了异常
确切地说,这是我得到的错误: 线程“主”中的异常java.io.FileNotFoundException:文件:/ Working Directory / Work / Work-Prof / CLineProject / CLINE / bin / main / org / cline / contract / purchases / Customer.json(无此类文件或目录)
但是当我遵循此路径时,文件位于确切的位置
它已经可以在Windows操作系统上运行,但不能在MacOS Mojave上运行
public static void main(String[] args) throws Exception {
public static String CUSTOMER_JSON = initializeVariables("Customer.json");
}
private static String initializeVariables (String _fileName) {
//Getting the file from the resources folder;
URL conversionVariable = Main.class.getResource(_fileName);
String convertedVariable = "", newName = "";
try
{
//Converting URL to URI
URI uri = conversionVariable.toURI();
//type-casting the URI to a string
convertedVariable = uri.toString();
//replacing "%20" with a white space
newName = convertedVariable.replaceAll("%20", " ");
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return newName;
}
它应该给我用于获取条目的JSON文件的路径。但是它抛出了上述例子