import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.rtf.RTFEditorKit;
public class Readrtf {
public Rrtf(){
}
/**
* @param filePath 文件路径
* @return 读出的rtf的内容
*/
public static String getTextFromRtf(String filePath) {
String result = null;
File file = new File(filePath);
try {
DefaultStyledDocument styledDoc = new DefaultStyledDocument();
InputStream is = new FileInputStream(file);
new RTFEditorKit().read(is, styledDoc, 0);
result = new String(styledDoc.getText(0,styledDoc.getLength()).
getBytes("ISO8859_1"));
//提取文本,读取中文需要使用ISO8859_1编码,否则会出现乱码
} catch (IOException e) {
e.printStackTrace();
} catch (BadLocationException e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String filePath="E:\\34.rtf";
System.out.println(getTextFromRtf(filePath));
}}这是读取rtf的代码,但是有一些问题,不能读出部分中文标点符号,帮忙解决解决,谢谢大家!
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.rtf.RTFEditorKit;
public class Readrtf {
public Rrtf(){
}
/**
* @param filePath 文件路径
* @return 读出的rtf的内容
*/
public static String getTextFromRtf(String filePath) {
String result = null;
File file = new File(filePath);
try {
DefaultStyledDocument styledDoc = new DefaultStyledDocument();
InputStream is = new FileInputStream(file);
new RTFEditorKit().read(is, styledDoc, 0);
result = new String(styledDoc.getText(0,styledDoc.getLength()).
getBytes("ISO8859_1"));
//提取文本,读取中文需要使用ISO8859_1编码,否则会出现乱码
} catch (IOException e) {
e.printStackTrace();
} catch (BadLocationException e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String filePath="E:\\34.rtf";
System.out.println(getTextFromRtf(filePath));
}}这是读取rtf的代码,但是有一些问题,不能读出部分中文标点符号,帮忙解决解决,谢谢大家!
解决方案 »
- jsp中,td单元格如何斜着一分为二?
- 在高并发下,struts2 报一下错误,请大家看下什么原因,谢谢,在线等!!!
- 关于tomacat中运用java反射机制
- subclass's has not only one entity manager property帮我看看这个异常怎么解决?
- GlassFish 下面的问题
- restful+jax-rs+eclipse3.5的问题
- 一个struts的异常
- hibernate一对多的问题?
- struts配置数据源的问题
- 晕了晕了又晕了:Java技术有多少分支:j2ee,j2me,serlet,javabean?平常说的学习Java,都是什么意思?
- 西安Java培训完,做过项目是否找工作更容易些?
- java反射获取指定的构造方法出错,是为什么呢?
import java.io.*;
public class readAndWrite
{
private BufferedReader bufferReadin=new BufferedReader(new FileReader("D:/CSDN/34.rtf"));
String s=null;
public readAndWrite()throws IOException
{
while((s=bufferReadin.readLine())!=null)//
{
System.out.println(s);
}
bufferReadin.close();
}
public static void main(String[] args) throws IOException
{
readAndWrite Test=new readAndWrite();
}
}