开发者

Java File Appender write to windows network share

开发者 https://www.devze.com 2023-02-20 01:22 出处:网络
I am setting up the log4j logger in my code using a fileappender (see code below) FileAppender qappender = new FileAppender();

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

精彩评论

暂无评论...
验证码 换一张
取 消