The Artima Developer Community
Sponsored Link

Java Answers Forum
files

1 reply on 1 page. Most recent reply: May 14, 2002 6:12 AM by Tarba Dan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Maysoon

Posts: 64
Nickname: hm
Registered: Mar, 2002

files Posted: May 14, 2002 12:02 AM
Reply to this message Reply
Advertisement
hello all..


how can i delete any type of file?

what is the problem with the following code:


RandomAccessFile file1=new RandomAccessFile("d:/file.text");
File f=new File("d:/file.text");
f.delete();


the file created and did not deleted ,so what is the problem?


please help,thanks..


Tarba Dan

Posts: 11
Nickname: dtarba
Registered: May, 2002

Re: files Posted: May 14, 2002 6:12 AM
Reply to this message Reply
The class RandomAccessFile supports 2 constructors :

RandomAccessFile(File file, String mode)
Creates a random access file stream to read from, and optionally to write to, the file specified by the File argument.

RandomAccessFile(String name, String mode)
Creates a random access file stream to read from, and optionally to write to, a file with the specified name.

The constructor you used RandomAccessFile(java.lang.String) does not exist.

If you remove the line
RandomAccessFile[\b] file1=new RandomAccessFile[\b] ("d:/file.text");
then your code will work and the file will be deleted .

If you want to keep that line then close te file like this :

RandomAccessFile file1=new RandomAccessFile("d:/file.text");

//close the file before opening it again :
file1.close();

//now you can open the file
File f=new File("d:/file.text");

//and delete it
f.delete();

Flat View: This topic has 1 reply on 1 page
Topic: Please Help! Previous Topic   Next Topic Topic: mix languages in Java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use