简体   繁体   English

无法将文件写入服务器

[英]Unable to write file to the Server

I wrote the below code inorder to write an xml output to a file in my Tomcat Server. 我编写了以下代码,以便将xml输出写入到Tomcat服务器中的文件中。 When I ran the code I get the below error. 当我运行代码时,出现以下错误。 May I know what is wrong in my code. 我可以知道我的代码有什么问题吗? Thanks in advance. 提前致谢。 It is supposed to create a directory with name test and then the file test.xml in the path I specified in my server. 应该在我在服务器中指定的路径中创建一个名称为test的目录,然后创建文件test.xml。 But, it is not doing doing that and instead it is looking for that path in my local machine 但是,它没有这样做,而是在我的本地计算机中寻找该路径。

java.io.FileNotFounException: C:\\test\\test.xml The system cannot find the path specified java.io.FileNotFounException:C:\\ test \\ test.xml系统找不到指定的路径

   // write the content into xml file
                 TransformerFactory transformerFactory = TransformerFactory.newInstance();
                 Transformer transformer = transformerFactory.newTransformer();
                 DOMSource source = new DOMSource(doc);

                 StreamResult result = new StreamResult(new File("/test/test.xml"));
                 transformer.transform(source, result);

                 // Output to console for testing
                 StreamResult consoleResult = new StreamResult(System.out);
                 transformer.transform(source, consoleResult);

By default Tomcat set value of java.io.tmpdir system property to its tmp directory. 缺省情况下,Tomcat将java.io.tmpdir系统属性的值设置为其tmp目录。 So the following piece of code should create a File object pointing to a file in Tomcat tmp: 因此,以下代码应创建一个指向Tomcat tmp中文件的File对象:

String tempDir = System.getProperty("java.io.tmpdir");
File outputFile = new File(tempDir, "test.xml");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM