簡體   English   中英

無法將文件寫入服務器

[英]Unable to write file to the Server

我編寫了以下代碼,以便將xml輸出寫入到Tomcat服務器中的文件中。 當我運行代碼時,出現以下錯誤。 我可以知道我的代碼有什么問題嗎? 提前致謝。 應該在我在服務器中指定的路徑中創建一個名稱為test的目錄,然后創建文件test.xml。 但是,它沒有這樣做,而是在我的本地計算機中尋找該路徑。

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);

缺省情況下,Tomcat將java.io.tmpdir系統屬性的值設置為其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