小编Tan*_* H.的帖子

Java:在新File()中传递String变量;

我正在开发一个桌面应用程序,它使用XPath读取特定的XML元素并将其显示在文本字段中JFrame.

到目前为止,程序运行顺利,直到我决定StringFile类中传递一个变量.

public void openNewFile(String filePath) {
    //file path C:\\Documents and Settings\\tanzim.hasan\\my documents\\xcbl.XML 
    //is passed as a string from another class.
    String aPath = filePath;

    //Path is printed on screen before entering the try & catch.
    System.out.println("File Path Before Try & Catch: "+filePath);

    try {
        //The following statement works if the file path is manually written. 
        // File xmlFile = new File ("C:\\Documents and Settings\\tanzim.hasan\\my documents\\xcbl.XML");

        //The following statement prints the actual path  
        File …
Run Code Online (Sandbox Code Playgroud)

java string file new-operator

6
推荐指数
1
解决办法
3471
查看次数

标签 统计

file ×1

java ×1

new-operator ×1

string ×1