小编典典

为什么此读取器读取奇怪的数据位?

java

我正在尝试读取文本文件,我正在使用fileImputStream,并将所有行读取到单个String中,然后将其输出到控制台(System.out)

当我尝试读取humanSerf.txt时,它在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

如何使怪异的文字消失?

这是我正在使用的代码,请帮助

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中完成的


阅读 287

收藏
2020-11-23

共1个答案

小编典典

我认为您的文本文件不是纯文本,而是支持格式的RTF文件。查看时,您可能会使用支持RTF的工具,例如TextEdit。如果您查看的内容少或多,您还应该看到RTF标记。

2020-11-23