Update 1:- Hello guys, I found some people are not able to suggest anything cuz the question is not so clear.
So I simplified the code for them and able to reproduce it again. Now all you need is just to ctrl c and ctrl v and set the property file accordingly.
package com.test;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.ResourceBundle;
public class ReproduceIssue {
static {
try {
String propertyFilePath = "/home/jioapp/apache-tomcat-7.0.56";
File file1 = new File(propertyFilePath);
URL[] urls = { file1.toURI().toURL() };
ClassLoader loader = new URLClassLoader(urls);
ResourceBundle resourceBundle = ResourceBundle.getBundle("TinyOffline",Locale.getDefault(), loader);
String timestamp = new SimpleDateFormat("dd.MM.yyyy-HH.mm.ss").format(new Date());
/** Note: If file already open, moving no longer possible. */
String logFileAbsolutePath = resourceBundle.getString("log4j.absolute.file.path");
System.out.println(logFileAbsolutePath); /** /home/jioapp/apache-tomcat-7.0.56/OfflineLog/TinyOffline.log */
File file = new File(logFileAbsolutePath);
System.out.println(file);/** \home\jioapp\apache-tomcat-7.0.56\OfflineLog\TinyOffline.log */
System.out.println(file.exists());/** false */
if (file.exists()) {
String renameToFile = logFileAbsolutePath + "." + timestamp;
if (!file.renameTo(new File(
renameToFile))) {
System.out.println("Renaming log file failed : " + logFileAbsolutePath);
}
} else {
System.out.println("Unable to open log file : "
+ logFileAbsolutePath);
}
/** Note: If Piwik file already exist then rename it **/
String piwikLogFileAbsolutePath = resourceBundle.getString("sys.piwik.absolute.file.path");
System.out.println(piwikLogFileAbsolutePath);/** /home/jioapp/apache-tomcat-7.0.56/PiwikLog/access.log */
File piwikFile = new File(piwikLogFileAbsolutePath);
System.out.println(piwikFile);/** \home\jioapp\apache-tomcat-7.0.56\PiwikLog\access.log */
System.out.println(piwikFile.exists());/** true */
if (piwikFile.exists()) {
if (!piwikFile.renameTo(new File(piwikLogFileAbsolutePath + "."
+ timestamp))) {
System.out.println("Renaming piwik log file failed : "
+ logFileAbsolutePath);
System.out.println("Stopping the services....");
System.exit(0);
}
} else {
System.out.println("No Piwik access log file exist :"
+ piwikLogFileAbsolutePath);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
TinyOffline.properties
log4j.absolute.file.path=/home/jioapp/apache-tomcat-7.0.56/OfflineLog/TinyOffline.log
sys.piwik.absolute.file.path=/home/jioapp/apache-tomcat-7.0.56/PiwikLog/access.log
I think this might help.
Java JDK-7.0.79