?? fileutil.java
字號:
package com.huiton.cerp.pub.util;
/**
* Title: CERP測試框架
* Description:
* Copyright: Copyright (c) 2000
* Company: BRITC
* @author 吳劍
* @version 1.0
*/
import java.io.*;
public class FileUtil {
/**
* 復制文件
*/
public static void copyFile(String srcFile, String destFile)
throws IOException
{
RandomAccessFile rfRead=null;
RandomAccessFile rfWrite=null;
try {
rfRead = new RandomAccessFile(srcFile, "r");
rfWrite = new RandomAccessFile(destFile, "rw");
byte[] b = new byte[1];
int flag = rfRead.read(b);
for(int i=0;flag!=-1;i++) {
rfWrite.write(b);
flag = rfRead.read(b);
}
}
catch(IOException e) {
e.printStackTrace();
}
finally {
rfRead.close();
rfWrite.close();
}
}
/**
* 刪除文件
*/
public static boolean deleteFile(String fileName) throws IOException {
File fl = new File(fileName);
return fl.delete();
}
/**
* 刪除文件路徑
*/
public static boolean deleteFileInSequence(String fileName,String rootDir) throws IOException {
boolean bl=true;
if(fileName.lastIndexOf("/")==fileName.length()){
fileName.substring(0,fileName.lastIndexOf("/"));
}
if(rootDir.lastIndexOf("/")==rootDir.length()){
rootDir.substring(0,rootDir.lastIndexOf("/"));
}
File fl = new File(fileName);
String tempFileName=fileName;
System.out.println("tempFileName="+tempFileName);
while(bl&&!tempFileName.equals(rootDir)){
bl=fl.delete();
int pos=tempFileName.lastIndexOf("/");
tempFileName=tempFileName.substring(0,pos);
System.out.println("tempFileName="+tempFileName);
fl=new File(tempFileName);
}
return bl;
}
/**
* 創建子目錄
*/
public static boolean makeDir(String dirName) throws IOException {
boolean bl=true;
if(dirName.lastIndexOf("/")!=dirName.length()){
dirName=dirName.concat("/");
//System.out.println("dirName="+dirName);
}
int pos=0;
String temp=new String();
while(dirName.lastIndexOf("/")>pos){
pos=dirName.indexOf("/",pos+1);
temp=dirName.substring(0,pos);
//System.out.println("tempDirName="+temp);
File fl = new File(temp);
if(!fl.isDirectory())
bl=fl.mkdir();
}
return bl;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -