📄 business.java
字号:
package common;import java.io.*;import java.util.*;public class Business { int hour; public Business() { } /** * 此方法实现重命名文件 * @param oldname String * @param newname String * @return boolean */ public boolean renameTo(String oldname, String newname) { try { File oldfile = new File(oldname); if (!oldfile.exists()) { return (false); } else { oldfile.renameTo(new File(newname)); } return (true); } catch (Exception ex) { ex.printStackTrace(); return (false); } } /** * 此方法产生一个唯一文件名 * @param oldname String * @return String */ public String getNewName(String oldname) { try { String newName = null; String exName = null; String now = null; int index = oldname.lastIndexOf("."); if (index != -1) { exName = oldname.substring(index, oldname.length()); Calendar cNow = Calendar.getInstance(); if (cNow.get(Calendar.AM_PM) == cNow.get(Calendar.AM)) { hour = cNow.get(Calendar.HOUR) + 12; } now = "" + cNow.get(Calendar.YEAR) + (cNow.get(Calendar.MONTH) + 1) + cNow.get(Calendar.DATE) + hour + cNow.get(Calendar.MINUTE) + cNow.get(Calendar.SECOND) + cNow.get(Calendar.MILLISECOND); newName = now + exName; newName = this.getPath(oldname) + "\\" + newName; return (newName); } else { return (oldname); } } catch (Exception ex) { ex.printStackTrace(); return (null); } } /** * 此方法返回文件的路径 * @param filename String * @return String */ public String getPath(String filename) { try { String filepath = null; int index = filename.lastIndexOf("\\"); filepath = filename.substring(0, index); return (filepath); } catch (Exception ex) { ex.printStackTrace(); return (filename); } } /** * 此方法实现得到指定路径的文件名 * @param file String * @return String */ public String getName(String file) { try { String path = null; int index = file.lastIndexOf("\\"); if (index != -1) { path = file.substring(index + 1, file.length()); return (path); } else { return (file); } } catch (Exception ex) { ex.printStackTrace(); return (file); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -