📄 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 + -