1.首先确定 从文本到程序 不是乱码(通过设定程序读取的编码格式,或者另存文件的编码格式)
/** * 查找文件夹下所有符合txt的文件 * * @param dir 要查找的文件夹对象 * */ public void findFile(File dir) throws Exception { File[] dirFiles = dir.listFiles(); Map<String,ArrayList<String>> typemap=getTypeList(new File(typeResource));//初始化 事件种类 for(File temp : dirFiles){ if(!temp.isFile()){ findFile(temp); } //查找指定的文件 if(temp.isFile() && temp.getAbsolutePath().endsWith(".txt") ){ //System.out.println(temp.isFile() + ":" +temp.getName()+":"+ temp.getAbsolutePath()); String txtName=temp.getName().substring(0,temp.getName().indexOf("."));//得到文件名字 String content=getText(temp);//取得文档的内容 String strgetString(temp,"hello");//取"hello"后面的字符串 ArrayList arr=getArrList(temp);//将文本内容按“,” 结成字符串数组 } } }
public String getText(File file) throws Exception { InputStre