Results 1 to 6 of 6
Thread: .exists URGENT
- 12-12-2012, 11:28 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 6
- Rep Power
- 0
.exists URGENT
Hi!
I'm trying to create a file before writing/reading to/from it. I always get an error that the package (although it is a file) doesn't exist. My code is as follows:
File myFile = new File(System.getProperty("user.dir") + File.separator
+ "\\output\\Daganalyse.pdf");
File parentDir = myFile.getParentFile();
if(parentDir.isDirectory())
{
parentDir.mkdirs();
}
(it turns red at the 'if')
Please help me!
Thank you!
- 12-12-2012, 11:36 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: .exists URGENT
What turns 'red at the if'? Nothing else? You must be using a lousy IDE.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-12-2012, 11:39 AM #3
Member
- Join Date
- Dec 2012
- Posts
- 6
- Rep Power
- 0
Re: .exists URGENT
Netbeans gives error at the 'if':
illegal start of type
package parentDir does not exist
<identifier> expected
';' expected
thanks for the quick response!
- 12-12-2012, 11:43 AM #4
Member
- Join Date
- Dec 2012
- Posts
- 6
- Rep Power
- 0
Re: .exists URGENT
and of course, the correct code is: if (!parentDir.isDirectory()) (and I have the same problem with .exists), but it still turns red
- 12-12-2012, 12:02 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: .exists URGENT
Are those statements part of a method body?
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-12-2012, 03:22 PM #6
Member
- Join Date
- Dec 2012
- Posts
- 6
- Rep Power
- 0
Re: .exists URGENT
I've already been able to solve the problem by using different coding:
Thank you for your help!Java Code:static String datum = "14-13-2012"; static String pathDir = "H:\\Weekanalyses"; //static String pathFile = "H:\\Weekanalyses\\newfile" + datum +".txt"; static int i =0; static String pathFile = "H:\\ Leveranciers\\GoedkoopsteLeveranciers-" + i + ".txt"; public static void main(String[] args) {File f = new File(pathDir); try{ if(f.exists()==false){ f.mkdir(); System.out.println("Directory Created"); } else{ System.out.println("Directory is not created"); } }catch(Exception e){ e.printStackTrace(); } try { File file = new File(pathFile); if (file.createNewFile()){ System.out.println("File is created!"); }else{ System.out.println("File already exists."); } } catch (IOException e) { e.printStackTrace(); }Last edited by quad64bit; 12-12-2012 at 04:26 PM. Reason: Added code tags
Similar Threads
-
Help with knowing if .split()[1] exists
By trath in forum New To JavaReplies: 1Last Post: 08-29-2012, 09:28 PM -
do set and get methods really exists?
By ronnie in forum New To JavaReplies: 3Last Post: 02-22-2012, 06:07 PM -
Determining which choice exists
By kjkrum in forum XMLReplies: 1Last Post: 12-16-2011, 12:27 AM -
How do I check if a database exists ...Any help?
By nmvictor in forum New To JavaReplies: 5Last Post: 05-09-2010, 04:21 PM -
[URGENT]SHA Encryption System...need urgent helps
By java_idiot in forum New To JavaReplies: 6Last Post: 05-02-2010, 10:04 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks