为什么java 用IO流读docx文件里的内容打印在控制台是乱码
import java.io.BufferedReader;import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Linx {
public static void inPut(File file,String str) throws IOException{
Reader rd=new FileReader(file);
BufferedReader reader=new BufferedReader(new BufferedReader(rd));
byte[] buf=new byte[1024];
int i=1;
String sr="";
Pattern p=Pattern.compile(str);
Matcher m=null;
while((sr=reader.readLine())!=null){
m=p.matcher(sr);
while(m.find()){
System.out.println();
System.out.println("第"+i+"处 "+file.getPath());
System.out.println("----------------------------------------------------------------------------");
i++;
}
}
reader.close();
rd.close();
}
public static void isDirectory(File file,String str) throws FileNotFoundException, IOException{
if(file.isDirectory()){
String [] gf=file.list();
for(int i=0;i<gf.length;i++){
isDirectory(new File(file,gf[i]), str);
// System.out.println(new File(file,gf[i]));
//System.out.println(file.getPath()+"\\"+gf[i]);
}
}else{
inPut(new File(file.getPath()), str);
}
}
public static void main(String[] args) throws FileNotFoundException, IOException {
isDirectory(new File("E:\\我的项目\\学生管理"),"click");
}
}
其它文件不会出现乱码?*.docx就会出现看不懂的乱码?有没有高手解决一下,小弟先谢过了! --------------------编程问答-------------------- io读取确实是乱码 。 你用poi解析 docx文件的对象吧
补充:Java , Java相关