Results 1 to 7 of 7
Thread: Exist or not exist file problem
- 12-26-2010, 05:56 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
Exist or not exist file problem
Hi there.
So, i have some text writeen on a textpane and now i want to save it as a document but my problem is how to know if the file is already saved or not on the disc.
If the file is already on it i just want to "update" it and if it's not i want to create the file and put the text there...
Can anyone give me some tips to solve this ?
-
Have you looked at the Java File class? What have you tried? How isn't it working?
- 12-26-2010, 06:48 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
I have a method that is something like this...
File file=new File(path);
String path = f.getPath();
boolean exists = file.exists();
if (!exists) {
create and save the the file.
}else{
the file exists so i just need to save it.
}
This is not working but i don't know very well how to do it right because of the file and path variables... :confused:
-
Can you give us more information on what is specifically not working? Those methods work for me, and I can't tell based on what you've posted what you're doing wrong.
- 12-26-2010, 07:02 PM #5
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
I don't understand your last line [“This is not working but i don't know very well how to do it right because of the file and path variables...”], but is any exception thrown, if not, what values does ‘exists’ get?
I'm not sure, but I think ‘f.getPath()’ returns the relative path you fed the constructor;
however, ‘f.getAbsolutePath()’ returns the absolute path and ‘f.getCanonicalPath()’ returns the absolute path a the file the path points to, so normally the file at your path, but if is a link in Unix-like OS:es it returns the absolute path of the file the link links to.
- 12-26-2010, 07:25 PM #6
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
I have text on a textpane. When i hit the save button i want to know if the file already exists on the disk because in that case i want to update that file and if that file does not exists in the disc i want to create it with the text which is inside the textpane.
What i post throws this exception -> Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- 12-26-2010, 07:29 PM #7
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
Similar Threads
-
Japplet.getImage(): What if image file does not exist?
By CoderMan in forum Java AppletsReplies: 0Last Post: 02-11-2010, 11:31 PM -
HttpClientLibrary does not exist
By gbose in forum NetworkingReplies: 1Last Post: 02-03-2010, 07:21 PM -
java.io.File - Files do not exist
By TannerLD in forum New To JavaReplies: 8Last Post: 09-10-2009, 12:03 AM -
package mj does not exist
By PzK in forum New To JavaReplies: 8Last Post: 12-03-2008, 10:30 PM -
problem with viewing .java files when Visual J# 2005 Express Edition exist
By unhurt in forum New To JavaReplies: 3Last Post: 11-03-2007, 01:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks