在Java中读取RTF文件时出错

时间:2016-06-08 20:01:21

标签: java rtf

从RTF文件中读取内容并将其转换为String格式。我收到以下异常。

Exception in thread "main" java.lang.NumberFormatException: For input string: "-"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:572)
at java.lang.Integer.parseInt(Integer.java:615)
at javax.swing.text.rtf.RTFParser.write(RTFParser.java:249)
at javax.swing.text.rtf.RTFParser.write(RTFParser.java:135)
at javax.swing.text.rtf.AbstractFilter.write(AbstractFilter.java:173)
at javax.swing.text.rtf.AbstractFilter.readFromStream(AbstractFilter.java:106)
at javax.swing.text.rtf.RTFEditorKit.read(RTFEditorKit.java:82)
at com.coseer.whatsapp.CoseerProject.FetcherData.convertFileToString(FetcherData.java:57)

代码是:

RTFEditorKit rtf = new RTFEditorKit();
    Document doc = rtf.createDefaultDocument();
String sa="";
    FileInputStream fis = new FileInputStream(inputfile);
    try {
        rtf.read(fis,doc,0);
          sa=doc.getText(0,doc.getLength());
          System.out.println(sa);
            return sa;
    } catch (BadLocationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "";
    }

我得到一个例外:rtf.read(fis,doc,0);

0 个答案:

没有答案