package com.fgkj.dto; import java.io.File; public class MyFile { private File file; private String fileName; //文件名称 private String filePath; //文件路径 private String fileType; //文件类型 public void initFile(){ this.fileName = file.getName(); this.filePath = file.getAbsolutePath(); this.fileType = getFileTypeFromFile(this.file); } public String getFileTypeFromFile(File source){ String[] str = source.getAbsolutePath().split("\\."); return str[str.length-1]; } public File getFile() { return file; } public void setFile(File file) { this.file = file; initFile(); } public String getFileName() { return fileName; } public void setFileName(String fileName) { this.fileName = fileName; } public String getFilePath() { return filePath; } public void setFilePath(String filePath) { this.filePath = filePath; } public String getFileType() { return fileType; } public void setFileType(String fileType) { this.fileType = fileType; } @Override public String toString() { return "MyFile [file=" + file + ", fileName=" + fileName + ", filePath=" + filePath + ", fileType=" + fileType + "]"; } }