我有一個用java編寫的服務器,它偵聽特定的端口號。我也有一個Objective-C客戶端連接到這個服務器並進行通信。溝通工作正常。現在,我必須從終端獲取objective-c客戶端的輸出並將其放入由java服務器創建的文件中。我如何去做這件事?普通的FileWriter函數似乎不起作用。以下是我擁有的服務器的一部分。將客戶機的控制檯輸出寫入服務器中的文件
// Get the client message
while((inputLine = bufferedReader.readLine()) != null) {
System.out.println(inputLine);
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//read a line from the console
String lineFromInput = in.readLine();
File file = new File("./user_statistics.txt");
if(!file.exists()){
file.createNewFile();
}
//create an print writer for writing to a file
fileWriter = new FileWriter(file);
//output to the file a line
fileWriter.write(lineFromInput);
}
//close the file
fileWriter.close();
serverSocket.close();
這是行不通的?你有沒有收到任何錯誤信息?它創建一個空文件還是什麼? – 2014-11-01 01:42:02
它創建一個空文件...它不會寫入任何文件 – vasupradha 2014-11-01 01:46:10