java - 从命令行执行 Jar 文件,文件夹名称中包含空格

标签 java jakarta-ee

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)
at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(Unknown Source) at com.org.FileSepratorTest.main(FileSepratorTest.java:16)

它没有显示整个文件路径,我知道我需要将此作为参数,但我想执行 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.  

最佳答案

"- 双引号将文件路径括起来

E:\TestCode\executable_jar>java -cp E:\TestCode\executable_jar\abc_lib -jar redmas- migration.jar "E:\TestCode\Migration Letest File\abc.xml"

关于java - 从命令行执行 Jar 文件,文件夹名称中包含空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24796467/

相关文章:

java - 使用 JSTL c :out ${expression} 动态评估表达式

java - 调用 servlet 时不转发

java - 使用 hibernate 对有序数据进行分页

java - JFileChooser 的 Windows 外观

jbehave/storyDurations.props 的 java.io.FileNotFoundException

java - 用于设置方向的 PJL 命令

java - 这是某些类型的方法变量吗?

java - maven-jboss-plugin怎么用?如果我想部署war怎么办?

java - 如何将字节数据转换为位并再次转换回字节?

java - 当我将图像存储在谷歌驱动器上时如何在我的项目中显示缩略图