PrintWriter不打印字符串,而是打印空白行

时间:2014-05-23 20:07:52

标签: java io printwriter

在第20行,PrintWriter不会打印附加到'hold'变量的字符串。 'hold'变量是正确的,因为它稍后会用适当的字符串打印到控制台两行。有关PrintWriter打印空行的原因吗?

代码:

public void accepter() throws IOException{

    handler han =  new handler();
    Thread thread2 = new Thread(han);  
    FileWriter fw = new FileWriter(transferFile, true);
    PrintWriter writer = new PrintWriter(fw);

    System.out.println("Reciver started");
    thread2.start();

    while(true){

        aSocket = sSocket.accept();
        input = new BufferedReader(new InputStreamReader(aSocket.getInputStream()));

        hold = input.readLine();

        if(hold != null){

            writer.println(hold);
            writer.flush();
            System.out.println(hold);

        }
    }
}

0 个答案:

没有答案