• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

RE:queries in files

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,



1)how to delete the contents of the files?

randomaccessfile rm=new randomaccessfile("rw"); is the answer?

please give me the right answer?


2)how to change the current working directory?


can we use chdir,cd or there is no method to change it directly?


please give me the lines of code for the above 2 questions
 
Marshal
Posts: 76870
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vidya Bhargavi wrote:. . .
randomaccessfile rm=new randomaccessfile("rw"); is the answer?. . .

Unless you have created your own class, that won't even compile, so No.
Have you read the API specifications? Or the Java™ Tutorials?

2)how to change the current working directory?


can we use chdir,cd or there is no method to change it directly?

Why on earth would you want to change the working directory?
 
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vidya Bhargavi wrote:1)how to delete the contents of the files?

randomaccessfile rm=new randomaccessfile("rw"); is the answer?


No it isn't. That will open the file for reading and writing but will not change its contents.

I know two ways to do this:
1) use FileChannel.truncate to set the size to 0.
2) use a FileOutputStream and don't write anything to it.

2)how to change the current working directory?

can we use chdir,cd or there is no method to change it directly?


Try using setProperty("user.dir", "new path");
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic