阅读了Java文档(我承认是pythonista)后,似乎没有一种确定特定文件中使用的行尾编码的干净方法。
我推荐的最好的办法是使用
BufferedReader.read()并遍历文件中的每个字符。像这样:
String filename = ...br = new BufferedReader( new FileInputStream(filename));while (true) { String l = ""; Char c = " "; while (true){ c = br.read(); if not c == "n"{ // do stuff, not sure what you want with the endl encoding // break to return endl-free line } if not c == "r"{ // do stuff, not sure what you want with the endl encoding // break to return endl-free line Char ctwo = ' ' ctwo = br.read(); if ctwo == "n"{ // do extra stuff since you know that you've got a rn } } else{ l = l + c; } if (l == null) break; ... l = "";}


