?? utiltool.java
字號:
/**
*
*/
package com.justin.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author Justin
*
*/
public class UtilTool {
//文件復制
public static void copyFile(String inFilePath, String outFilePath)
throws IOException {
FileInputStream fin = null;
RandomAccessFile fout = null;
try {
fin = new FileInputStream(inFilePath);
fout = new RandomAccessFile(outFilePath, "rw");
FileChannel in = fin.getChannel();
FileChannel out = fout.getChannel();
MappedByteBuffer input = in.map(FileChannel.MapMode.READ_ONLY, 0,
in.size());
MappedByteBuffer output = out.map(FileChannel.MapMode.READ_WRITE,
0, in.size());
output.put(input);
} finally {
try {
if (fin != null)
fin.close();
} catch (IOException ex) {
}
try {
if (fout != null)
fout.close();
} catch (IOException ex) {
}
}
}
//獲取指定格式的當前時間
//"yyyy-MM-dd HH:mm:ss"
public static String getCurTime(String timeFormat) {
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat(timeFormat);
return dateFormat.format(date);
}
//重命名文件,path是文件所在的文件夾路徑
public static boolean renameFile(String path, String fromName, String toName){
return new File(path + File.separator + fromName).renameTo(new File(path + File.separator + toName));
}
//測試方法
/*
public static void main(String[] args) {
try {
copyFile("D:\\ExcelFile\\test1.xls", "E:\\xu.xls");
System.out.println("successful");
}
catch (IOException ex){
System.err.println(ex);
}
}
*/
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -