I am out of luck with my JAVA Application executed from MATLAB. In short I have following code:
try {
dir = new File("Patients/Patient" + patientNumber + "/Meals");
dir.mkdirs();
.... more code goes here
} catch (Exception e) {
System.out.println("Some Error");
For some reason, and I do not know why, this code runs perfectly when executed from the JAVA main method. However, from MATLAB this piece of code does not work. It terminates at dir.mkdirs()
and hence never creates the directory. I had success using mkdirs()
and mkdir()
many times before, so, I suspect the problem exist in MATLAB. Do you have any idea what is the reason?
Stack Trace:
e.printStackTrace();
Returns following:
java.io.FileNotFoundException: Patients\Patient1\Meals\meal0.csv (The system cannot find the path specified.)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileWriter.<init>(Unknown Source)
at inputOutput.PrintPatientCsv.printMealCsv(PrintPatientCsv.java:57)
at inputOutput.CreatePopulation.createpopulation(CreatePopulation.java:54)
at functionality.FactoryModel.loadData(FactoryModel.java:100)
The last three lines is a product of the directory not created. However, I am not certain of the meaning of the top 4 lines in above code.
Program details
My Java program is created inside a .jar
file. This .jar
file is located in:
C:\Users\myName\program\binJava
my matlab (where I execute the .jar
file from) file is located in:
C:\Users\myName\program\matlab
In my MATLAB I type following:
clear all
javaaddpath('..\binJava\myFile.jar')
import functionality.*;
import domain.*;
import test.*;
import inputOutput.*;
function.MyFunction(1,2,3);
The reason for the import statements is that my program is build into 4 different packages.
*UPDATE: * I just found out that the program works if I create absolute directory as sugested by lnunno. This still does not solve the problem though.