为什么这个读者会读出奇怪的数据? [英] why does this reader read off strange bits of data?
问题描述
我正在尝试读取文本文件,我正在使用fileImputStream,并将所有行读入单个String,然后将其输出到控制台(System.out)
I'm trying to read a text file, i'm using fileImputStream, and reading all the lines into a single String then outputing it into the console (System.out)
当我尝试阅读humanSerf.txt时,它在consol中给我这个:
When I try to read the humanSerf.txt, it gives me this in the consol:
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf360
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\paperw11900\paperh16840\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural
\f0\fs24 \cf0 symbol=HS\
strength=15\
agility=13\
constitution=7\
wisdom=9\
intelligence=5}
在文本文件中,它说:
symbol=HS
strength=15
agility=13
constitution=7
wisdom=9
intelligence=5
如何让奇怪的文字消失?
How do I make the weird text disappear?
这是我正在使用的代码,请帮助
this is the code i'm using, please help
try{
// Open the file that is the first
// command line parameter
FileInputStream read = new FileInputStream("resources/monsters/human/humanSerf.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(read);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
如何让奇怪的文字消失?
ps,这是在mac textedditor中完成的
How do I make the weird text disappear? ps, this was done in mac textedditor
推荐答案
我认为你的文本文件不是纯文本而是<一个支持格式化的href =http://en.wikipedia.org/wiki/Rich_Text_Format =noreferrer> RTF 文件。当您查看它时,您可能使用支持RTF的工具,例如TextEdit。如果您使用less或cat查看它,您还应该看到RTF标记。
I think your text file is not plain text but rather a RTF file which supports formatting. When you view it you probably use a tool which supports RTF, such as TextEdit. If you view it with less or cat you should also see the RTF markup.
这篇关于为什么这个读者会读出奇怪的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!