I have a program that takes values from a property file(host,port), the path of the property file is currently beign hard coded, but I want to be able to compile and place the property file in the same directory as my compiled classes(in bin/) and when I make a jar and run the program,it should take the values from there automatically, how do I do that?
You should be able to use a "copy" task to copy the property file in your bin directory, inside the same package directory as the java file that needs to read the properties. Then, jar the program, using the "jar" task.
In the java program, you should now be able to read the properties in this way:
Properties props = new Properties();
props.load(getClass().getResourceAsStream("my.properties"));
String host = props.get("hostname");
String port = props.get("port");
Related
I am currenly working on an erlang project and stuck in reading the file. I want to read a text file which is in the /src folder where all the erlang and a text file are in the same structure. Then too, I am not being able to read the file despite of specifying file paths. Any help would be appreciated.
start() ->
{ok,DataList} = file:consult("Calls.txt"),
io:format("** Calls to be made **"),
io:fwrite("~w~n",[DataList]).
The data file stores contents like : {john, [jill,joe,bob]}.
Try add folder name to the path or try set full patch to the file:
1> {ok,DataList} = file:consult("src/Calls.txt").
Notes: the error {error,enoent} mean that the file does not exist or you don't have a rights to read/write current file, for this case need set 777 rights or similar.
If you need to use src/call.txt, then this simply means that your IDE (or you) has created a src folder in which the calls.txt file has been placed. At the same time, the IDE is using a path that only includes the top level folder (i.e., the root folder for the IDE project). So src/call.txt must be used in that case. This isn’t a problem with Erlang, or even the IDE. It’s just the way your project is set up.
You can do either of two things. Move the calls.txt file up one level in the IDE file manager, so that it can be referenced as calls.txt, not src/call.txt. You can also just change the path to “calls.txt” before you run it from the command line.
enoent means "Error: No Entry/Entity". It means the file couldn't be found. When I try your code, it works correctly and outputs
[{john,[jill,joe,bob]}]
I can successfully download a file from my ftp server using:
ftp.get(chosenFile,chosenFile);
Where chosenFile is simply a string with the name of the file.
However these are downloaded to the Debug folder of my Delphi project so...
1.) How can I specify where the files should be downloaded to.
2.) How can I make TOpenDialog automatically open to that location after downloading?
You can specify a full path in the destination file, to specify the exact location. You can specify that same path as the initial dir of the open dialog.
You could also set the working directory using the SetCurrentDir procedure.
Alternatively, you can use ftp.Get(chosenFile, Stream), where Stream can be an instance of any TStream descendant, like a TFileStream (opened to write to your desired target file), or even a TMemoryStream, if you don't need the file to be on disk at all.
In fact, the Get overload that accepts the destination filename, will just create a TIdFileStream, depending on the exact parameters, and call the other overload.
[SOLVED] I solved my own problem, can't believe it was so simple:
1.Specify the director where the file should be downloaded to as the second parameter: ftp.get(chosenFile,'C:\Temp\'+chosenFile);
2.Set the initial directory of the TOpenDialog as follows: dlg.InitialDir := 'C:\Temp';
How to write ant script to get a substring from one property file and copy in another property file?
For Eg. I am getting oracle_12c in a property file but now I want to store oracle in one value and 12c in another value in a property file.Can anyone suggest how to write antscript for this.
I have a build file, which has the following property in it.
<property name="schema.dir" value="src/main/resources/schema" />
This schema.dir is used to refer a wsdl file.The parent folder which contains the build.xml has a space in it like this folder name .
When I echoed the property it displayed only src/main/resources/schema.
But I can see from the ant logs that issue is with the space in the folder name.
Since the parent folder is having a space in it, I am not able to refer the wsdl.
Can somebody suggest a solution so that file can be accessed with out changing the folder name
Is it possible to provide directly full path to wsdl file?
Try to replace " " sign with "%20".
For test you can hardcode that and with ANT you can use the propertyregex task from Ant Contrib.
See Replacing characters in Ant property
Have you tried specifying your property as a location rather than a string so Ant knows it's dealing with a file path, you can also specify the path as relative to your base directory.
<property name="schema.dir" location="${basedir}/src/main/resources/schema"/>
Adding ${basedir} to the path may not be necessary after changing the property from a value to a location.
I know how to get the basename for a file with java's ANT build tool, but in this case I want to change the name of a file to include a build version number. Unfortunately the file's name gets set in another ant script (from the android system) which I am importing and I'm not able to set the property for that file or the imported script will complain that the property should not be set already. Thus, if i have a property holding MyApp-release.apk and I want to change the value to MyApp-release-1.10.apk how would I do this? I know I can put the 1.10 at the start of the filename with basename and that's probably what I will do, but I'd rather do it the other way.
Form http://ant.apache.org/manual/Tasks/basename.html:
Task to determine the basename of a specified file, optionally minus a
specified suffix.
<basename property="cmdname" file="D:/usr/local/foo.exe"
suffix=".exe"/>