[英]Executing Jar file from command line with spaces in folder name
Input File Path as argument to program
File Path : E:\TestCode\Test file space\abc.xml
Code : This code will accept the above file path as argument.
package com.org;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class FileSepratorTest {
public static void main(String[] args) {
String filePath = args[0]; // It will take file path as E:\TestCode\Test file space\abc.xml
try {
System.out.println("File Path :"+filePath); // printing file path
FileInputStream file = new FileInputStream(new File(filePath));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Exception occurs when execute this code with space separated folder name
File Path :E:\TestCode\Test
java.io.FileNotFoundException: E:\\TestCode\\Test (The system cannot find the file specified)
java.io.FileNotFoundException:E:\\ TestCode \\ Test(系统找不到指定的文件)
at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(Unknown Source) at com.org.FileSepratorTest.main(FileSepratorTest.java:16)at java.io.FileInputStream.open(Native Method)at java.io.FileInputStream。(Unknown Source)at com.org.FileSepratorTest.main(FileSepratorTest.java:16)
It's not showing whole file path, I know I need to take this as arguments but I want to execute jar file, jar file path specified as follows 它没有显示整个文件路径,我知道我需要把它作为参数但是我想执行jar文件,jar文件路径指定如下
E:\TestCode\executable_jar>java -cp E:\TestCode\executable_jar\abc_lib -jar redmas- migration.jar E:\TestCode\Migration Letest File\abc.xml** **in my application.
Surround your file path with " - double quote
使用
" - double quote
环绕文件路径
E:\\TestCode\\executable_jar>java -cp E:\\TestCode\\executable_jar\\abc_lib -jar redmas- migration.jar "E:\\TestCode\\Migration Letest File\\abc.xml"
E:\\ TestCode \\ executable_jar> java -cp E:\\ TestCode \\ executable_jar \\ abc_lib -jar redmas- migration.jar“E:\\ TestCode \\ Migration Letest File \\ abc.xml”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.