I try to create an ResXResourceWriter instance. using this code
ResXResourceWriter resxWriter = new ResXResourceWriter(filepath);
The file is located in local resources folder.
How to write the path?
Related
I am using Choose File keyword to upload file. In documentation is written that I can use ${CURDIR} to set the path to my file, but it means that this file has to be in the same directory ${CURDIR}/filename.txt. But how to set the path to the file that exists in another directory?
Use ${EXECDIR} so you go back to the root and go from there.
my web application project (JBoss AS) needs to read a file which resides outside of this project. For example, the file to be read is under /tmp/.
It looks like classes in the project can't access files under /tmp/. However, it can output to a file in /tmp/.
Is this normal? How to access /tmp/ directory in a Web application?
Use java.io.tmpdir system property.
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
//Use tmpDir to access files in tmp directory
Make sure there are unix permissions to read/write contents on tmp directory.
I have a problem regarding exporting my Java project into a jar file.
I have this file (application.properties) which contains some database information and located under the project root directory.
There is no problem when running this project on Eclipse. But after exporting into a jar(Runnable Jar file) file, application.properties will not be included in the packaging and that cause the error.
Any suggestion how to fix this problem?
Do you want to have the application.properties reside outside the jar (for writing), or is it read-only? When outside you can have an initial template file in the jar, and copy it to some location.
//String applicationWorkingDir = System.getProperty("user.dir"); // The current constellation.
String userHomeDir = System.getProperty("user.home");
File myApplicationDataDir = new File(userHomeDir + "/.MyApplication");
myApplicationDataDir.mkdir();
File propertiesFile = new File(myApplicationDataDir, "application.properties");
Also using the Preferences API instead of a properties would be a solution.
I created a jar file from a Java project. I can even run it now, but it does not save the serialization file that is stored correctly when I run the program from normal binary code outside of the JAR file.
Can’t you create new files when you have a jar file?
This is how I write the file:
FileOutputStream fileOut = new FileOutputStream("data/vocabulary.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(this);
out.close();
fileOut.close();
My JAR file looks like this:
META-INF
MANIFEST.MF
name
stefankoch
…
where name/stefankoch/… is my project namespace.
I tried creating a data directory in the jar-file (root), but it did not work either. There also is a data directory within the directory the jar-file resides in, but that one is not taken either.
How can I allow jar files to create files?
basically, you should not add information entered by the user into a JAR file, they belong to the user’s home directory.
This can be read with
System.getProperty("user.home")
And files within the user home directory can also be used from within a JAR file.
I am processing some CSV file which i have copied in Bin folder of My ASP.NET Website.
When i execute
using (IDataReader csv = new CsvReader
(new StreamReader("sample.txt"), true, '|'))
{
.....
}
it complains me that "sample.txt" not found in "c:\Program Files\.....\"
Won't the runtime automatically look into the bin folder?
what modification do i need to do?
You need to specify a full path by calling Server.MapPath:
new StreamReader(Server.MapPath(#"~/bin/sample.txt"))
However, you should not put anything in the bin folder other than assemblies.
You should use the App_Data folder instead.