| Author |
Files--simple doubt
|
Jenny raj
Ranch Hand
Joined: May 19, 2005
Posts: 57
|
|
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
|
 |
Nigel Browne
Ranch Hand
Joined: May 15, 2001
Posts: 673
|
|
|
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
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24061
|
|
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 ]
|
[Jess in Action][AskingGoodQuestions]
|
 |
Jenny raj
Ranch Hand
Joined: May 19, 2005
Posts: 57
|
|
Hi ernest your explanation is very clear,thank u
|
 |
Vladimir Nesov
Greenhorn
Joined: Jun 18, 2006
Posts: 20
|
|
|
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.
|
 |
 |
|
|
subject: Files--simple doubt
|
|
|