如何在调用Files.readAllLines时保留行终止符

时间:2016-03-11 17:59:27

标签: java file

我正在逐行解析文件:

List<String> lines = Files.readAllLines(Paths.get(fileName), StandardCharsets.UTF_8);

问题是我需要在每行的末尾保留行终止符(因为我需要对文件中的某些行进行一些“引用可打印”解码,并且行终止符在这些行中很重要例)。

我的文件格式如下:

From: test2@test.com
To: test@test.com
Subject: Email subject
Content-Type: text/plain; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: quoted-printable


Please see the following articles:

Joe Ben, Wed, 6/6:  Businesses vie for blackout exemptions:=20
The PUC must decide who should be spared, and the applicant list is very lo=
ng

Joe Bem, Wed, 6/6: PG&E, ISO agree to court order on power bills

Sac Bee, Wed, 6/6:  Peter Schrag: Turning up the heat in Houston and=20
Washington  (Editorial)

我可以将整个文件作为一个字节数组读取,但这对我来说很不方便,因为我可以更方便地将电子邮件中的标题解析为文本行。

0 个答案:

没有答案