Calling a java class file using batch file works fine.
Here is the code which is working.
public class TestA {
public static void main(String[] args) {
new TestA().printA();
}
public void printA(){
System.out.println("This is A...");
try {
File file = new File("D:/FileA.txt");
boolean fvar = file.createNewFile();
if (fvar){
System.out.println("File has been created successfully");
}
else{
System.out.println("File already present at the specified location");
}
} catch (IOException e) {
System.out.println("Exception Occurred:");
e.printStackTrace();
}
}
}
The same above code if I put it on scheduling using task executors and try calling the same file using batch file, it's not working ( I mean here file creation is not happening). Need your help on this.
Code with scheduling:
public class TestD implements Runnable {
private ScheduledExecutorService executor = null;
@Override
public void run() {
try {
File file = new File("D:/FileD.txt");
boolean fvar = file.createNewFile();
if (fvar){
System.out.println("File has been created successfully");
}
else{
System.out.println("File already present at the specified location");
}
} catch (IOException e) {
System.out.println("Exception Occurred:");
e.printStackTrace();
}
}
public void executeScheduler() throws SQLException {
executor.scheduleAtFixedRate(this, 2, 5, TimeUnit.SECONDS);
}
public static void main(String args[]){
TestD testD = new TestD();
try {
testD.executeScheduler();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I wrote the code to create a file just to test if my code is being called from the batch file or not, as I couldn't observe the system out statements which are shown in cmd prompt in a jiffy.
Edit:
The reason for this problem is due to NullPointerException
but the exception is not able to capture as I'm calling the file using batch and the cmd window not showing the error or probably it's showing the error but not human capturable and window closes in fraction of a second. So I don't think this question is a duplicate of What is a NullPointerException, and how do I fix it?