为什么我的日志没有';t仅在writer(Java)中在记事本中显示换行符

为什么我的日志没有';t仅在writer(Java)中在记事本中显示换行符,java,Java,我正在用Java开发一个应用程序,它捕获字符串并生成日志文本 public static void createTXTLog(String pathLog, String textLog){ try{ BufferedWriter writer = new BufferedWriter(new FileWriter(pathLog)); writer.write(textLog); writer.close(); } cat

我正在用Java开发一个应用程序,它捕获字符串并生成日志文本

public static void createTXTLog(String pathLog, String textLog){
    try{
        BufferedWriter writer = new BufferedWriter(new FileWriter(pathLog));
        writer.write(textLog);
        writer.close();
    }
    catch(Exception e){
        System.out.println("An error occured while generating log txt: \n" + e.toString());
    }
}
当我打开此方法生成的日志时,它在记事本中显示如下内容:

09-12-2013 17:48:18 :[INF] Creando la conexion a la BD... 09-12-2013 17:48:18 :[eW003][ERR][inicioProceso] Error en la creacion de la conexion a la BD: java.sql.SQLException: Listener refused the connection with the following error:ORA-12505, TNS:listener does not currently know of SID given in connect descriptor The Connection descriptor used by the client was:180.176.40.134:1522:DBDESAS
但如果我在Writer上打开它,它会正确显示:

09-12-2013 17:48:18 :[INF] Creando la conexion a la BD... 

09-12-2013 17:48:18 :[eW003][ERR][inicioProceso] Error en la creacion de la conexion a la BD: 
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
180.176.40.134:1522:DBDESAS
你知道如何在记事本上修复它吗???
提前感谢

您的问题是您只返回一条新线,而不是回车和新线;这是Windows文本文件所需的。您可以将此更改为以下内容

System.out.println("An error occured while generating log txt:" + System.lineSeparator() + e);
或者,如果您运行的不是Windows,而是Windows中的记事本,您可以这样做

System.out.println("An error occured while generating log txt: \r\n" + e);

我冒昧地删除了多余的
toString()
调用。

您的问题是您只返回了一个新行,而不是回车和换行;这是Windows文本文件所需的。您可以将此更改为以下内容

System.out.println("An error occured while generating log txt:" + System.lineSeparator() + e);
或者,如果您运行的不是Windows,而是Windows中的记事本,您可以这样做

System.out.println("An error occured while generating log txt: \r\n" + e);

我擅自删除了冗余的
toString()
调用。

这肯定是因为您使用了
“\n”
而不是Windows中的行分隔符
“\r\n”

这肯定是因为您使用了
“\n”
而不是
”\r\n
Windows中的哪一行分隔符。

不同的操作系统有不同的行分隔符:您在哪里编写实际的换行符?请注意,BufferedWriter有一个
.newLine()
方法,如果您不想手动写入换行符,可以使用该方法。使用PrintWriter而不是BufferedWriter/FileWriter也可以为您提供编写换行符的方便方法。Notepad.exe是地球上最愚蠢的程序,仅次于cmd.exe。使用更好的工具来查看你的文件,比如utraedit甚至jedit。不同的操作系统有不同的换行符:你在哪里写实际的换行符?请注意,BufferedWriter有一个
.newLine()
方法,如果您不想手动写入换行符,可以使用该方法。使用PrintWriter而不是BufferedWriter/FileWriter也可以为您提供编写换行符的方便方法。Notepad.exe是地球上最愚蠢的程序,仅次于cmd.exe。使用更好的工具查看您的文件,如utraedit甚至jedit。