分享

java.io.IOException: 文件名、目录名或卷标语法不正确。

 _bolo 2016-08-19
[TestNG] Running:
  E:\Selenium\hnabi\src\resources\com\hnabi\xml\testng.xml

srcFile 2016-08-19 05:03:39-test.png
java.io.IOException: 文件名、目录名或卷标语法不正确。
at java.io.WinNTFileSystem.canonicalize0(Native Method)
at java.io.Win32FileSystem.canonicalize(Win32FileSystem.java:414)
at java.io.File.getCanonicalPath(File.java:618)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1079)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1038)
at com.hnaweb.dto.ResponseWebDriverDto.screenshot(ResponseWebDriverDto.java:62)
at com.hnaweb.unit.LoginTest.luch(LoginTest.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
at org.testng.TestRunner.beforeRun(TestRunner.java:656)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at com.hnaweb.unit.XmlAssess.main(XmlAssess.java:29)

源码
        Date date = new Date();
        DateFormat ExcuteTime_FILE_NAME = DateFormat.getDateTimeInstance(DateFormat.ME         DIUM, DateFormat.MEDIUM);
调用输出的结果 srcFile 2016-08-19 05:03:39-test.png
但是,File文件不能创建带有特殊字符的文件,导致的出错;

修改后:
        Date date = new Date();
        DateFormat df =new SimpleDateFormat("yyyy-MM-dd hh-mm-ss");
        String imgName = df.format(date)+ ".png";
调用输出后的结果 srcFile 2016-08-19 05-03-39-test.png

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多