原是抄的大神的源码,东拼西凑的找了大半天,已忘记原链接了。特此声明⭐️本人不生产代码,只是代码的搬运工。
/**
* 用换行符讲读取的整个文档内容截取成若干字符串
*/
public static String[] interfacePath;
// 读取本地文件内容
public static void chars() throws Exception {
String str= readRtf();
interfacePath = str.split("\n");
for (i = 0; i < interfacePath.length; i++) {
System.out.println(interfacePath[i]);//将被分割的字符串输出
}
return;
}
/**
* 读取本地rtf文件
*/
public static String readRtf() {
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"),"GBK");
//注意这边加上GBK即可;
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
标签:interfacePath,MacOS,rtf,Java,String,styledDoc,new,读取 From: https://www.cnblogs.com/JojoMiss/p/18111657