|
Attention! Read the forum rules carefully before posting a topic.
Try to find an answer in Wiki before asking a question. Submit programming questions in this forum only. Off topics are strictly forbidden.
Any topics which do not satisfy these rules will be deleted.
| Write a file |
|
Guest
|
| Post subject: Write a file |
Post rating: 0
|
Posted: Thu 14 Aug, 2008, 17:04
|
|
User rating: -
|
|
With previous version of API, I could write an Excel file (named data.xls) with the following code :
print("data.xls",bar.close +" ; " +bar.open);
I did not find in new API documentation the way to do that. Can you help me ?
Thank you
|
|
|
|
|
 |
|
API Support
|
| Post subject: Re: Write a file with new API |
Post rating: 0
|
Posted: Fri 15 Aug, 2008, 08:56
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
The problem with previous API was the access restrictions, that didn't allow to write files on disc. To bypass this restriction we added our own functionality to write files with print method. In new API you can add @RequiresFullAccess annotation before declaration of main strategy class. This will remove all the access restrictions and you can use standard Java ways to write files. For example you can write: try { File file = new File("C:/NameOfMyNewFile.txt"); FileWriter fw = new FileWriter(file); fw.write("content of my file"); fw.close(); } catch (IOException e) { e.printStackTrace(); }
remember to add import java.io.*; to be able to use io classes.
|
|
|
|
|
 |
|
[DarkMan]
|
| Post subject: Re: Write a file with new API |
Post rating: 0
|
Posted: Fri 15 Aug, 2008, 19:51
|
|
User rating: 0
Joined: Thu 27 Mar, 2008, 13:06 Posts: 18
|
|
In documentation for RequiresFullAccess is listed that "if only need to read/write to file - you have full access to "~/My Documents/My Strategies/files" folder. In this folder you can read or write any file without requesting the full access." But I don't know how I can locate "My Strategy" folder, I can't use full path because it's located in profiles and strategy will use more people. Do you have any constant or method for this folder?
Thanks DarkMan
|
|
|
|
|
 |
|
API Support
|
| Post subject: Re: Write a file with new API |
Post rating: 0
|
Posted: Mon 18 Aug, 2008, 09:20
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
In our code we use FileSystemView.getFileSystemView().getDefaultDirectory() public static File getMyStrategiesDir() { File myDocs = FileSystemView.getFileSystemView().getDefaultDirectory(); File dir = new File(myDocs.getPath() + File.separator + "My Strategies"); if (!dir.exists()) { dir.mkdirs(); } return dir; }
|
|
|
|
|
 |
|
[DarkMan]
|
| Post subject: Re: Write a file with new API |
Post rating: 0
|
Posted: Wed 24 Sep, 2008, 15:10
|
|
User rating: 0
Joined: Thu 27 Mar, 2008, 13:06 Posts: 18
|
|
With last version of API I can't write into "My Strategies" folder without @RequireFullAccess. In previous version I could create files and folder in "My Strategies" folder. (java.io.FilePermission C:\Documents and Settings\user\My Documents\My Strategies read)
|
|
|
|
|
 |
|
API Support
|
| Post subject: Re: Write a file with new API |
Post rating: 0
|
Posted: Thu 25 Sep, 2008, 08:48
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
You have access only to "to C:\Documents and Settings\user\My Documents\My Strategies\files" folder.
|
|
|
|
|
 |
|
SFXbernhard
|
| Post subject: Re: Write a file |
Post rating: 0
|
Posted: Sun 13 Jun, 2010, 13:39
|
|
User rating: 21
Joined: Thu 19 May, 2011, 20:50 Posts: 413 Location: Germany, Munich
|
If I try to write a file into the upper mentioned path I always get an AccessControlException. Quote: 12:27:13 java.security.AccessControlException: access denied (java.io.FilePermission C:\Users\SFXbernhard\Documents\My Strategies\files\test.dat read)
I found a solution. You have to take the directory, which is set in the properties menu of the JForex app. Writeable path: [strategies path set in JForex properties]/files/ But how can I retrieve this [strategies path set in JForex properties] ?
|
|
|
|
|
 |
|
API Support
|
| Post subject: Re: Write a file |
Post rating: 0
|
Posted: Mon 14 Jun, 2010, 08:51
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
|
 |
|
SFXbernhard
|
| Post subject: Re: Write a file |
Post rating: 0
|
Posted: Tue 15 Jun, 2010, 23:57
|
|
User rating: 21
Joined: Thu 19 May, 2011, 20:50 Posts: 413 Location: Germany, Munich
|
|
Thanks, but how can I access IContext within an indicator program?
|
|
|
|
|
 |
|
API Support
|
| Post subject: Re: Write a file |
Post rating: 0
|
Posted: Wed 16 Jun, 2010, 12:09
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
You can't. Indicators are supposed to only make some calculation on some input data and give some output. That's it. All other stuff, need to be placed in a strategy.
|
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|