2014-07-17 50 views
1
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 \测试(系统找不到指定的文件)
在java.io.FileInputStream.open (本机方法) 在java.io.FileInputStream中。(来源不明) 在com.org.FileSepratorTest.main(FileSepratorTest.java:16)从命令行执行Jar文件与文件夹名称空间

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

试一下:java -cp E:\ TestCode \ executable_jar \ abc_lib -jar redmas- migration.jar”E:\ TestCode \ Migration Letest File \ abc.xml“ – chf

+0

使用双引号“路径”来包含路径 –

+0

感谢您的帮助,它按预期工作。 –

回答

2

环绕与" - double quote

你e文件的路径:\ TestCode \ executable_jar> java命令E:\ TestCode \ executable_jar \ abc_lib 罐子redmas- migration.jar“E:\ TestCode \迁移Letest文件\ abc.xml“