• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Files--simple doubt

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String dirName="c:/java";
File f=new File(dirName,"Work.txt");


what does the above line do?
does it create a new file name work.txt in a specified directory c:/java
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The way to find your answer is to look up the Javadocs for the class File, find the constructor that takes two strings as its parameters and then read the descriptive text.Javadocs link
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The File class probably should be named "Path" or "FilePath". Creating a java.io.File doesn't create a file -- it creates a path that could refer to a file. Yes, this File object will refer to the file "C:\java\work.txt". The file doesn't necessarily exist unless you force it to exist -- for example, by opening and closing a FileOutputStream with it (which would create a zero-length file

FileOutputStream os = new FileOutputStream(f);
os.close();

Of course, this would destroy the file if it already existed; you could test for this using f.exists().
[ June 27, 2006: Message edited by: Ernest Friedman-Hill ]
 
Jenny raj
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ernest
your explanation is very clear,thank u
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that the whole point of File is abstraction of system-specific path naming rules, so don't do things like new File("C:\my_folder"). Such things should be outside the code.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic