File fff = new File("E:\\yanjiusheng\\data\\2017.3.9\\5Apriori\\fenRules\\"+getFileNameNoEx(f.getName()));
if (!fff.exists()) {
// 如果路径不存在,则创建
fff.mkdirs();
}
FileWriter fw = null;
try{
for(int i = 0 ; i < topicNum; i ++){

fw = new FileWriter("E:\\yanjiusheng\\data\\2017.3.9\\5Apriori\\fenRules\\"+getFileNameNoEx(f.getName())+"\\"+ i+".txt");

 

fw.write("内容");

 

}//for i
fw.close();
} catch (IOException e) {
e.printStackTrace();
}

//遍历文件夹下的每个文本文件
public static List<File> getFiles(String path) {
File root = new File(path);
List<File> files = new ArrayList<File>();
if (!root.isDirectory()) {
files.add(root);
} else {
File[] subFiles = root.listFiles();
for (File f : subFiles) {
files.addAll(getFiles(f.getAbsolutePath()));
}
}
return files;
}

/*
* Java文件操作 获取不带扩展名的文件名
*/
public static String getFileNameNoEx(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot >-1) && (dot < (filename.length()))) {
return filename.substring(0, dot);
}
}
return filename;
}

posted on 2017-03-20 13:32  honey-78  阅读(284)  评论(0编辑  收藏  举报