I want to append into the existing text file. For that I have tried all this in plenty of way FileWriter,BufferedWriter,PrintWriter,RandomAccessFile,OutputStream,FileOutputStream,PrintStream but I can't get my desired output.
This error java.io.FileNotFoundException: could not open file '//file:/usr/backupdata/5605.txt' using mode 'a+' sucks. (I am working with ewon flexy hardware which supports javaetk 1.4 only)
You are trying to use a url as a file name. That won’t work.
Use
/use/backupdata/5605.txt
as the file name.
Related
I'm using Thymeleaf template engine, and want to get the charset attribute value for the meta tag on the head block from my project properties, i.e :
<meta th:charset="${#environment.getProperty('html.charset')}">
But when I want to save my html file I get this pop-up error :
Save could not be completed. Try File > Save As... if the problem persists.
Reason:
Character encoding "${#environment.getProperty('html.charset')}" is not a legal character encoding.
I even tried to save the file from outside of eclipse, but when back on eclipse and want to open the file, I couldn't access it and got this error :
Unsupported Character Encoding
Character encoding "${#environment.getProperty('html.charset')}" is not supported by this platform.
Set Encoding...
I tried to suspend all validators on eclipse Preferences but this doesn't resolve the problem.
Any ideas for help ? Thanks in advance.
I'm on Mac OS and using Eclipse IDE for Enterprise Java and Web Developers, Version: 2021-09 (4.21.0).
The charset value is being used, regardless of the prefix, to read and write the file correctly. That there is a prefix on the attribute in a non-prefixed meta tag is a clue that it should be ignored by the normal encoding detection. Please open a bug report for this.
For a workaround, force the use of the encoding you want using the file's Properties dialog's Resource page (get there by right-clicking on the file).
I have created an app using javaCv and
I'm trying to save an image in android using
cvSaveImage("/storage/sdcard0/watermarked/test.jpg", yCrCb);
cvSaveImage("/storage/extSdCard/test.jpg",yCrCb);
where yCrCb is an IplImage.
There is no exception error and the program runs smoothly but the files are not saved into the path as mentioned above.
I would like to ask what might be the possible problems ? is it the naming convention of the file name ?
If it helps, I have a java application counterpart of this app and the java version works fine when i use the line
cvSaveImage("C:\\testing123.jpg", yCrCb);
Hi I have used same thing for storing the image.
For getting the path to sdcard, I have used the Environment.getExternalStorageDirectory().toString();
append the folder name to this path where you want to store the image
try this and also make sure that you have written permission in the xml file.
Hi I am using Maven for Selenium automation tests using Java. I am using Excel Sheet to read data for filling up a registration form. Now It is a normal Maven archetype.
src
--main
--java
--mypackage for coding goes here.
--resources
--data
-- the excel sheet
--test
-- some stuff here under java
currently if I want to read a file I am writing src/main/resources/data/theexcelsheet.xlsx
but when I share this jar, I think this will break and I don't want this to break if I package this jar.
How do I make it platform or format independent.
I am using APACHE POI Api if you are thinking how I am reading files.
Someone reading gave me idea that I might be able to use MANIFEST files to do this but I am not sure, can someone help?
If you use getResource() to point to your file, the syntax of the path always uses / to separate the components, never \ so you do not have to worry.
In general, outside of a jar, for example if you want to save application settings in a folder, you have to use a OS specific separator - you can obtain it this way:
System.out.println("my" + File.separator + "dir");
Returns my\dir on Win and my/dir on Linux
Of course, that's not enough as you cannot use hardcoded paths like the "c:" drive, but you can get the most common paths reading the System class properties, eg:
System.out.println(System.getProperty("user.home"));
returns C:\Users\piero in Windows7 and /home/piero in Linux
I have for example .pdf file (path to that file). How to open this file in default application (probably Acrobat Reader) from SWT application (for example on Button click) ?
You should be able to use:
Program.launch(file);
to open the file (using the default application or creator). From the javadoc:
Launches the operating system executable associated with the file or URL (http:// or https://). If the file is an executable then the executable is launched. Note that a Display must already exist to guarantee that this method returns an appropriate result.
Note that there are some peculiarities in Program.launch() (or at least there were, though these may have been fixed in more recent versions of the runtime.) I don't really remember the specifics of the bugs, but we do some checks to work around some issues:
If you're on a Unix platform, and you're specifying an absolute path, there may be trouble opening that file. We prefix absolute paths with /. - so that /tmp/foo would be translated to /./tmp/foo - although I don't really remember the specifics of this bug any more than that.
On Windows, if you're trying to open a UNC path - for example \\server\bar - you need to wrap the string in double-quotes. For example: Program.open("\"\\server\bar\"");
Try Desktop.open:
Desktop.getDesktop().open(file);
Maybe this can help to find a decision: we ran into PermGen space trouble upon call Desktop.open() - which is in AWTpackage - out of our SWT application.
So I would prefer Program.launch() over Desktop.open() in a SWT-environment.
This is a very simple question for many of you reading this, but it's quite new for me.
Here is a screenshot for my eclipse
When i run this program i get java.io.FileNotFoundException: queries.xml (The system cannot find the file specified) i tried ../../../queries.xml but that is also not working. I really don't understand when to use ../ because it means go 1 step back in dir, and in some cases it works, can anyone explain this? Also how can I refer to queries.xml here. Thanks
Note: I might even use this code on a linux box
I assume it is compiling your code into a build or classes folder, and running it from there...
Have you tried the traditional Java way for doing this:
def query = new XmlSlurper().parse( GroovySlurping.class.getResourceAsStream( '/queries.xml' ) )
Assuming the build step is copying the xml into the build folder, I believe that should work
I don't use Eclipse though, so can't be 100% sure...
Try
file = new File("src/org/ars/groovy/queries.xml");
To check the actual working directory of eclipse you can use
File f = new File(".");
System.out.println(f.getAbsolutePath());
You could try using a property file to store the path of the xml files.
This way you can place the xml files in any location, and simply change the property file.
This will not require a change/recompilation of code.
This would mean you will only need to hardcode the path of the property file.
If you prefer not hardcoding the path of the property file, then you could pass it as an argument during startup in your server setup file. (in tomcat web.xml). Every server will have an equivalent setup file where you could specify the path of the property file.
Alternatively you could specify the path of the xml in this same file, if you don't want to use property files.
This link will show you an example of reading from property files.
http://www.zparacha.com/how-to-read-properties-file-in-java/