After compiler compiles class, it checks that the class implements IStrategy interface and has default constructor. To do so, it instantiates your class and does instanceof. The problem is, that at the moment when class is instantiated it fills all variables and calls GetPath() method to initialize defaultPath and does so with standard permissions. To fix this, you can change path.txt to "files/path.txt". It will work because you have access to the files directory by default. Or you can use variable of type File, then you will have button to select path to file in files selection dialog
package jforex;
import java.util.*;
import java.io.*;
import javax.swing.filechooser.*;
import com.dukascopy.api.*;
@RequiresFullAccess
public class GetPathTest implements IStrategy {
@Configurable("Enter the path to the settings file")
public String defaultPath = GetPath(); // try to get the user defined path from the file path.txt
/*
* Will have button to open file selection dialog
*/
@Configurable("My file")
public File myFile;
/*
* All txt files in My Strategies\files directory
*/
@Configurable(value="My txt files", fileType="*.txt")
public File myTxtFiles;
public void onStart(IContext context) throws JFException {
}
public void onAccount(IAccount account) throws JFException {
}
public void onMessage(IMessage message) throws JFException {
}
public void onStop() throws JFException {
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
public String GetPath() {
File StrategyFolder = getMyStrategiesDir(); //returns the full path to My Strategies folder inside My Documents
String strStratFolder = StrategyFolder.toString();
//print(strStratFolder);
String tmpPath = "C:\\temp";
File pathFile = new File(strStratFolder, "files/path.txt"); //should give the full path to the file in My Strategies\files
if (pathFile.exists()) {
try {
//print("path file exists");
FileReader fr = new FileReader(pathFile);
BufferedReader br = new BufferedReader(fr);
tmpPath = br.readLine();
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
} else {
//print("path file does not exist");
}
return tmpPath;
}
public static File getMyStrategiesDir() {
File myDocs = FileSystemView.getFileSystemView().getDefaultDirectory();
File dir = new File(myDocs.getPath() + File.separator + "My Strategies");
return dir;
}
}