一直显示:Gradle files have changed since last project sync. A project sync may be necessary for the IDE to work properly…对于有强迫症的我来说忍无可忍,明明没有动gradle文件,却一直显示这个,上Google询问时,看到stackoverflow有个答案,原来是文件修改时间比当前的晚.苦于要改的文件太多,于是搞了个工具类:
- 批量修改时间
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* Created by hejianfeng on 17/3/16.
*/
public class ModifyAll {
public static void main(String[] args) throws IOException {
List<File> folderList = new ArrayList<File>();
List<File> fileList = new ArrayList<File>();
File folder = new File("/Users/hejianfeng/AndroidStudioProjects/git");
FileVO baseFileVO = segregateFiles(folder);
fileList.addAll(baseFileVO.getFileList());
folderList.addAll(baseFileVO.getFolderList());
for (int i = 0; i < folderList.size(); i++) {
FileVO thisVO = segregateFiles(folderList.get(i));
fileList.addAll(thisVO.getFileList());
folderList.addAll(thisVO.getFolderList());
}
for (int i = 0; i < fileList.size(); i++) {
Date dte = new Date();
long milliSeconds = dte.getTime();
System.out.println("Setting Time For " + fileList.get(i) + " \nas " + milliSeconds);
fileList.get(i).setLastModified(milliSeconds);
}
for (int i = 0; i < folderList.size(); i++) {
Date dte2 = new Date();
long milliSeconds = dte2.getTime();
folderList.get(i).setLastModified(milliSeconds);
}
System.out.println("Succesfully Modified..!!!");
}
public static FileVO segregateFiles(File folder) {
List<File> folderList = new ArrayList<File>();
List<File> fileList = new ArrayList<File>();
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
fileList.add(listOfFiles[i]);
} else {
folderList.add(listOfFiles[i]);
}
System.out.println(listOfFiles[i]);
}
return new FileVO(fileList, folderList);
}
public static class FileVO {
List<File> fileList = new ArrayList<File>();
List<File> folderList = new ArrayList<File>();
public FileVO(List<File> fileList, List<File> folderList) {
this.fileList = fileList;
this.folderList = folderList;
}
public List<File> getFileList() {
return fileList;
}
public void setFileList(List<File> fileList) {
this.fileList = fileList;
}
public List<File> getFolderList() {
return folderList;
}
public void setFolderList(List<File> folderList) {
this.folderList = folderList;
}
}
}