• 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

I/O and Files

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ALL
When a file is created using the File class, does this file get destroyed when the program terminated or is this a permanent
file ???
Also, when you create a new file using the method createNewFile()
of the "File" class, in which directory does the file get
created ??

Thanks in advance.
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
This is my try
When a File object is created by using constructor of File class i think it creats an abstract object which get's destroyed when the programme exits.
Also when we use createNewFile() method , we call it on some file object right.and the file created depends on the object on which we r calling the method.if it represents object in current directory then it should create file in it and same goes for other directory objects
i hope this helps
I would welcome any comments on my answer
Regards Denish

[This message has been edited by denish mehta (edited April 11, 2001).]
 
Zahid, Butt
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thanks for your answer denish.
Do you have any code samples ??
Thanks in advance.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this.
--------
import java.io.*;
class MyFile
{
MyFile()
{
File f = new File("..\\"); //you can set the directory
File fnew = new File(f,"test1.txt");
try
{
fnew.createNewFile();
}catch (IOException ioe)
{}
}
static public void main(String[] a)
{
MyFile mf = new MyFile();
}
}
 
Zahid, Butt
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
James, what "exactly" does your code do ??
Thanks in advance.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Butt,
Your Question:
When a file is created using the File class, does this file get destroyed when the program terminated or is this permanent file?

Ans : File object is an abstract representation of file and directory pathnames so when you destroy File object then file will be permanent.
Your Question :
Also, when you create a new file using the method createNewFile() of the "File" class, in which directory does the file get created ??
Ans : createNewFile is instance method of File class so you have create File object. When you execute this method using File Object it atomically creates a new, empty file named by abstract pathname if and only if a file with this name does not yet exist. You can get path by using following instance method of File class public String getPath().createNewFile() method, in combination with the deleteOnExit() method, can therefore serve as the basis for a simple but reliable cooperative file-locking protocol.
 
reply
    Bookmark Topic Watch Topic
  • New Topic