I am setting up the log4j logger in my code using a fileappender (see code below)
FileAppender qappender = new FileAppender();
qappender.setFile("C:\logfile1.txt");
How do I get it to write a file to a p开发者_开发问答ublic windows network share like \\server1\path1\path2\log.txt
Map the network share to a virtual drive such as X:\path1\path2\log.txt
and then try writing.
Use a UNC path?
qappender.setFile("\\\\server\\share\\logfile1.txt")
(In Java string literals, \\
is the escape sequence for the character \
, so the above would write to the path \\server\share\logfile1.txt
)
Instead of using an File, you can use an OutputStream opened from a URL which you can access files from the network.
URL url = new URL("file://server1/file.txt");
URLConnection conn = url.openConnection();
OutputStream out = conn.getOutputStream();
精彩评论