2011-12-09 8 views
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のテキストエディタで行われました

+0

これはプレーンテキストファイルではないようです。あなたはそれをどのエディタで見ていますか? –

+1

RTF文書のテキストがコピーされているようです。実際には、プロパティー・ファイルを表示するためにどのエディターを使用しているかによって異なります。メモ帳などのプレーンテキストエディタで開いてみると、そこにも奇妙な書式があるはずです。 – Manish

+0

普通のテキストファイルではないようですが、RTF(リッチテキスト形式)のファイルで、書式設定などのための追加データを保存できます。 – HectorLector

答えて

5

あなたのテキストファイルは平文ではなく、書式設定をサポートするRTFファイルだと思います。それを見るときは、RTFをサポートしているツール(TextEditなど)を使用している可能性があります。 lessまたはcatで表示すると、RTFマークアップも表示されます。

+0

ありがとうございます。 –

関連する問題