package Test_Maya_Excel;
import java.io.File;
/**
* 扫描指定路径下面文件名字,并保存到指定的Excel中。
* 有待改进(GUI)
* @author HL
*
*/
public class Test_maya {
public static void main(String[] args) throws Exception {
// This is the path where the file's name you want to take.
String path = "E:\\Read";
getFile(path);
}
@SuppressWarnings("null")
private static void getFile(String path) throws Exception{
// get file list where the path has
File file = new File(path);
// get the folder list
File[] array = file.listFiles();
String[] str = new String [120];
for(int i=0;i
if(array[i].isFile()){ //如果是文件,遍历
// only take file name
System.out.println(array[i].getName());
str[i]=array[i].getName();
}else if(array[i].isDirectory()){ //如果是文件夹,遍历文件夹
getFile(array[i].getPath());
}
}
Maya_Excel.file_to_Excel(str,array.length);
}
}
package Test_Maya_Excel; import java.io.File; import java.io.IOException; import jxl.Workbook; import jxl.write.Label; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; class Maya_Excel{ public static void file_to_Excel(String[] str,int n) throws Exception { File file = new File("E:\\GetInfo\\现有场景汇总.xls"); //打开文件 WritableWorkbook book= Workbook.createWorkbook(file); //生成名为“第一页”的工作表,参数0表示这是第一页 WritableSheet sheet=book.createSheet("第一页",0); //在Label对象的构造子中指名单元格位置是第一列第一行(0,0) for(int i=0;i