java 读取FTP下的所有文件目录,并一递归的方式组成tree的数据格式保存到数据库中?求大神告诉一下该怎么写。本人很菜,求帮助?
package fileTranscoding;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
public class TransUtiltest {
private class A{
private int id;
private String fileName;
//文件类型0文件1文件夹
private String fileType;
//父文件ID
private int supperId;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getFileType() {
return fileType;
}
public void setFileType(String fileType) {
this.fileType = fileType;
}
public int getSupperId() {
return supperId;
}
public void setSupperId(int supperId) {
this.supperId = supperId;
}
@Override
public String toString() {
return "A [id=" + id + ", fileName=" + fileName + ", fileType=" + fileType + ", supperId=" + supperId
+ "]";
}
}
public static List<A> listA = new ArrayList<A>();
public void Trans(File file,int supperId) throws IOException{
String fileName = file.getName();
A a = new A();
a.setSupperId(supperId);
a.setId(++supperId);
a.setFileName(fileName);
if(file.isFile()){
a.setFileType("0");
}else if(file.isDirectory()){
a.setFileType("1");
File[] files = file.listFiles();
for(int i=0;i<files.length;i++){
Trans(files[i],supperId);
}
}else{
throw new RuntimeException("文件不存在");
}
listA.add(a);
}
public static void main(String[] args) throws IOException {
new TransUtiltest().Trans(new File("C:\\Users\\HUMMER\\Desktop\\七鱼测试文件"), 0);
System.out.println(TransUtiltest.listA);
}
}