1

私はテキストファイルを読み込もうとしています.fileImputStreamを使用しています.すべての行を単一の文字列に読み込んでからコンソールに出力します(System.out)

humanSerf.txt を読み取ろうとすると、コンソールに次のように表示されます。

{\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 で行われました

4

1 に答える 1

6

あなたのテキスト ファイルはプレーン テキストではなく、フォーマットをサポートするRTFファイルだと思います。表示するときは、おそらく TextEdit などの RTF をサポートするツールを使用します。less または cat で表示すると、RTF マークアップも表示されます。

于 2011-12-09T10:10:41.967 に答える