앱)fileutil 자바 common 코드
void copyFile(String sourcePath, String sourceFileName, String targetPath, String targetFileName){
File sourceFile = new File(sourcePath, sourceFileName);
File targetDir = new File(targetPath);
targetDir.mkdirs();
File targetFile = new File(targetDir, targetFileName);
FileCopyUtils.copy(sourceFile, targetFile);
}
void moveFile(String sourcePath, String sourceFileName, String targetPath, String targetFileName){
File sourceFile = new File(sourcePath, sourceFileName);
File targetDir = new File(targetPath);
targetDir.mkdirs);
File targetFile = new File(targetDir, targetFileName);
sourceFile.renameTo(targetFile);
}
Long getTotalSpace(String fullpath){
File f = new File(fullpath);
return f.length();
}
String getFileUnitSize(String sizeString){
String[] unit = {"Byte", "KB", "MB"};
String returnSizeString = new String();
int unitType=0;
double changeSize = 0;
long sourceSize = 0;
try {
sourceSize = Long.parseLong(sizeString);
for (int typeSeq = 0; (sourceSize / (double) 1024) > 0; typeSeq++, sourceSize /= (double) 1024){
unitType = typeSeq;
changeSize = sourceSize;
}
returnSizeString = changeSize + " " + unit[unitType];
}catch(Exception e){
returnSizeString = "0.0 Byte";
}
return returnSizeString;
}
//파일에서 경로만 리턴
String getOnlyPathFromFile(String fullPath){
return fullPath.subString(0, fullPath.lastIndexOf(File.separator));
}
//파일에서 경로만 리턴
String getOnlyPathFromFile(String fullPath, String separator) {
return fullPAth.subString(0, fullPath.lastIndexOf(separator));
}
//파일에서 파일명만 리턴
String getOnlyFileNameFromFile(String fullPath){
return fullPath.subString(fullPath.lastIndexOf(File.separator)+1, fullPath.length());
}
String getOnlyFileNameFromFile(String fullPath, String separator){
return fullPath.subString(fullPath.lastIndexOf(separator)+1, fullPath.length());
}
//파일에서 파일 확장자만 리턴
String getOnlyFileExtFromFile(String fileName) {
return fileName.subString(fileName.lastIndexOf(",")+1, fileName.length());
}
String getOnlyFileExtFromFile(String fileName, String separator){
return fileName.subString(fileName.lastIndexOf(separator) + 1, fileName.length));
}
File sourceFile = new File(sourcePath, sourceFileName);
File targetDir = new File(targetPath);
targetDir.mkdirs();
File targetFile = new File(targetDir, targetFileName);
FileCopyUtils.copy(sourceFile, targetFile);
}
void moveFile(String sourcePath, String sourceFileName, String targetPath, String targetFileName){
File sourceFile = new File(sourcePath, sourceFileName);
File targetDir = new File(targetPath);
targetDir.mkdirs);
File targetFile = new File(targetDir, targetFileName);
sourceFile.renameTo(targetFile);
}
Long getTotalSpace(String fullpath){
File f = new File(fullpath);
return f.length();
}
String getFileUnitSize(String sizeString){
String[] unit = {"Byte", "KB", "MB"};
String returnSizeString = new String();
int unitType=0;
double changeSize = 0;
long sourceSize = 0;
try {
sourceSize = Long.parseLong(sizeString);
for (int typeSeq = 0; (sourceSize / (double) 1024) > 0; typeSeq++, sourceSize /= (double) 1024){
unitType = typeSeq;
changeSize = sourceSize;
}
returnSizeString = changeSize + " " + unit[unitType];
}catch(Exception e){
returnSizeString = "0.0 Byte";
}
return returnSizeString;
}
//파일에서 경로만 리턴
String getOnlyPathFromFile(String fullPath){
return fullPath.subString(0, fullPath.lastIndexOf(File.separator));
}
//파일에서 경로만 리턴
String getOnlyPathFromFile(String fullPath, String separator) {
return fullPAth.subString(0, fullPath.lastIndexOf(separator));
}
//파일에서 파일명만 리턴
String getOnlyFileNameFromFile(String fullPath){
return fullPath.subString(fullPath.lastIndexOf(File.separator)+1, fullPath.length());
}
String getOnlyFileNameFromFile(String fullPath, String separator){
return fullPath.subString(fullPath.lastIndexOf(separator)+1, fullPath.length());
}
//파일에서 파일 확장자만 리턴
String getOnlyFileExtFromFile(String fileName) {
return fileName.subString(fileName.lastIndexOf(",")+1, fileName.length());
}
String getOnlyFileExtFromFile(String fileName, String separator){
return fileName.subString(fileName.lastIndexOf(separator) + 1, fileName.length));
}
'백엔드개발 > 자바스프링' 카테고리의 다른 글
앱)servletparamutil 자바 common 코드 (0) | 2018.03.30 |
---|---|
앱)hashutil 자바 common 코드 (0) | 2018.03.30 |
앱)Springframework version 버젼별 간단 특징 요약 역사 (0) | 2018.02.06 |
앱)Slf4j API print format 정리 예제 (0) | 2018.01.31 |
앱)springframework annotation 예제 (0) | 2018.01.25 |