Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何生成Java服务器从android客户端接收的日志文件?_Java_Logging_Text Files - Fatal编程技术网

如何生成Java服务器从android客户端接收的日志文件?

如何生成Java服务器从android客户端接收的日志文件?,java,logging,text-files,Java,Logging,Text Files,我这里有一个工作系统,它将我的android客户端与我的Java服务器进行通信。基本上,它只是通过我的android客户端发送消息,而我的服务器通过System.out.println(消息)接收消息。现在我想做的是将所有接收到的消息保存到一个文本文件中,作为我的日志,当我的服务器接收到一条新消息时,它将立即更新 while ((message = bufferedReader.readLine()) != null) { System.out.print

我这里有一个工作系统,它将我的android客户端与我的Java服务器进行通信。基本上,它只是通过我的android客户端发送消息,而我的服务器通过
System.out.println(消息)接收消息。现在我想做的是将所有接收到的消息保存到一个文本文件中,作为我的日志,当我的服务器接收到一条新消息时,它将立即更新

while ((message = bufferedReader.readLine()) != null) {
                    System.out.println("Message from " + message + " at " + dateFormat.format(cal.getTime()));
                    str.append(message+"\n");


                }
这是我的Java服务代码的一部分。顺便说一句,我使用TCP端口通过同一网络与服务器和客户端通信。我想将str字符串保留的文本保存到文本文件中。我该怎么做?还是有可能?提前谢谢

请查看我的代码:

PrintWriter out= new PrintWriter(new BufferedWriter(new FileWriter("C:/foo.txt")));
                while ((message = bufferedReader.readLine()) != null) {
                    System.out.println("Message from " + message + " at " + dateFormat.format(cal.getTime()));
                    str.append(message+"\n");
                    out.println(message);


                }

实现文件输出的一种简单方法是使用输出重定向运行服务器代码

java -cp<Whatever classpath> ServerClassName >file & 

我无法理解java-cpserverclassname>file这条语句&什么是类路径?我应该在哪里申报?你想看看我的全部代码吗?等等,我会更新帖子。我是说你是怎么执行代码的?它是从某种IDE还是从命令提示符运行?已更新@Akhilesh SinghJAVA ECLIPSE是我运行它的地方。
PrintWriter out= new PrintWriter(new BufferedWriter(new FileWriter("foo.out")));
while ( read message as you doing now)  {
    // do something 
    out.println(message);
    // do something
}