You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Rakhunathan <mr...@gmail.com> on 2016/02/20 18:58:34 UTC
Re: Build error java.lang.IllegalArgumentException: Negative time, at java.io.File.setLastModified(File.java:1344)
Not really sure why the problem occurs, but found out the solution. The
error occurs because, one or more file that you are trying to build, has a
negative time.(file.getLastModified() returns a negative value). If its a
huge project, might be hard to track which of them has gone wrong. Below
code might help
package com.example;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class ModifyAll {
public static void main(String[] args) throws IOException {
List<File> folderList = new ArrayList<>();
List<File> fileList = new ArrayList<>();
File folder = new File("D:/Rakhu/Copy/projectfolder/src");
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) + " as
" + milliSeconds);
fileList.get(i).setLastModified(milliSeconds);
}
System.out.println("Succesfully Modified..!!!");
}
public static FileVO segregateFiles(File folder) {
List<File> folderList = new ArrayList<>();
List<File> fileList = new ArrayList<>();
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);
}
}
FileVO.java
package com.example;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class FileVO {
List<File> fileList = new ArrayList<>();
List<File> folderList = new ArrayList<>();
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;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org