错误[STDERR]错误:\ Test_Reports \ Suite_Report.html(系统找不到指定的路径)?

时间:2015-01-27 13:04:55

标签: java eclipse jsp jboss5.x

我有一个旧的java项目。我为该项目创建了war文件。我修改了项目中给出的路径,例如:

........

    old path=ReportUtil.startTesting(System.getProperty("user.dir")+"//Test_Reports//Suite_Report.html");
    new path=ReportUtil.startTesting("/Test_Reports/Suite_Report.html");

.......

运行文件时显示如下消息:“ERROR [STDERR]错误:\ Test_Reports \ Suite_Report.html(系统找不到指定的路径)”。

我如何克服这个错误,我需要提前感谢大家的建议。

`HybridFramework.java
--------------------
public static void startTesting()
{
ReportUtil.startTesting("/Test_Reports/Suite_Report.html");
}



ReportUtil.java
----------------
public static void startTesting(String filename)
{
String indexResultFilename = filename;
String currentDir =  indexResultFilename.substring(0,indexResultFilename.lastIndexOf("/"));
FileWriter fstream =null;
BufferedWriter out =null;
try{
 fstream = new FileWriter(filename); //--------->here only showing the   error "The system cannot find the path specified"
 out = new BufferedWriter(fstream);
}
catch(Exception e)
{
 System.err.println("Error: " + e.getMessage());
}

}`

2 个答案:

答案 0 :(得分:0)

尝试new path=ReportUtil.startTesting("//Test_Reports//Suite_Report.html")

答案 1 :(得分:0)

//是可疑的,本来应该是/

我假设目录Test_Reports是手动创建的(并且在具有足够权限的Linux上)。

另请注意,FileWriter使用当前的平台编码。如果您想处理完整的Unicode,最好使用OutputStreamWriterStandardCharsets.UTF_8。在HTML中,应该添加一个对应的元字符集语句。