import java.io.*; public class TIME { public static void main(String[] args) { File oldName = new File("路徑/test.png"); File newName = new File(System.getProperty("user.dir")+"/截屏.png"); if(!oldName.exists()) { System.out.println("文件未檢測到,結束程序"); System.exit(0); } System.out.println("監測到截圖文件,准備轉移"); if(!oldName.renameTo(newName)) { System.out.println("文件轉移失敗"); System.exit(0); } System.out.println("文件轉移完畢,程序結束"); } }
參考:
https://www.cnblogs.com/sidesky/p/10487786.html java獲取當前路徑的幾種方法
https://blog.csdn.net/u010648555/article/details/78356040 Java File中renameTo的介紹和使用說明
https://blog.csdn.net/y_bing/article/details/82934847 java 文件操作