【发布时间】:2014-06-29 19:44:21
【问题描述】:
我设置了一个 FileReader,并打开了一个要读取的文件,但它给了我一个奇怪的输出,我似乎无法修复:
import java.io.BufferedReader;
import java.io.FileReader;
public class FileReading {
public static void main(String [] args) throws Exception {
FileReader file = new FileReader("/Users/danielpersonius/Desktop/test.rtf");
BufferedReader reader = new BufferedReader(file);
String text = "";
String line = reader.readLine();
while (line != null){
// So here, we want to print until it reaches 'null'
text += line;
line = reader.readLine();
}
System.out.println(text);
}
}
这是我的输出:
{\rtf1\ansi\ansicpg1252\cocoartf1265\cocoasubrtf200{\fonttbl\f0\fswiss\fcharset0 Helvetica;}{\colortbl;\red255\green255\blue255;}\margl1440\margr1440\vieww10800\viewh8400\viewkind0\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx\5760\tx648 tx8640\pardirnatural\f0\fs24 \cf0 测试}
TEST 是 rtf 文件所说的,但我如何摆脱我显然不想要的所有其他东西? 我在装有 OS X Mavericks 的 IMac 上
【问题讨论】:
-
>.
-
使用读取 rtf 的阅读器。
-
好的,我修好了,谢谢你的帮助。在我的 Mac 上,我使用 TextEdit,所以我就像你说的那样点击了“转换为纯文本”。谢谢
标签: java filereader