将rtf文件读入java并获取有关文件的奇怪信息

时间:2016-12-07 00:22:37

标签: java file rtf

这是我在文件中阅读的代码

Scanner inFile = null;
try {
    File file = new File("/Users/ChrisMyers/Desktop/res2.rtf");
    inFile = new Scanner(file);
    String line;
    while (inFile.hasNextLine())
    {
        line = inFile.nextLine();
        System.out.println(line);
    }
    inFile.close();
} catch (FileNotFoundException e) {
    System.out.println("File " + " not found!");
}

这就是打印出来的内容:

{\rtf1\ansi\ansicpg1252\cocoartf1504
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;\csgray\c100000;}
\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0

\f0\fs24 \cf0 what\
what\
what\
what}

我只想打印出来

what
what
what 
what

所有这些都在不同的行上。

0 个答案:

没有答案