• 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

code to write the command line arguments into a file

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i apologize for the previous post
problem here is i am getting only the last argument into the file (i think others are getting overwritten please anybody tell me how to avoid that overwriting )
meaning example :" hello world everyone" is the command line argumants
i want all the " hello world everyone" to be present in the file .

could anyone please help me out .
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i think others are getting overwritten please anybody tell me how to avoid that overwriting



Yes, it is getting overwritten... it would be a good idea to put the file opens and close, outside of the loop, as you only want to those once.

Henry
 
Sheriff
Posts: 22781
131
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
http://faq.javaranch.com/java/EaseUp
http://faq.javaranch.com/java/UseCodeTags
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And have a look at the FileWriter constructors.
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is what is happening ......
1. you are taking "hello" and writing it into the file. So file now contains "hello"
2. you are taking "world" and replacing all content in file with "world" So file now contains "world"
3. you are taking "everyone" and replacing all content in file with "everyone" So file now contains "everyone"

So, when you open the file, you have just one word "everyone" (which is clearly not expected)


what should have been done:

approach 1: StringBuffer
append all words into a String Buffer and then write this String Buffer into the file just once

approach 2: File Append
Open a file for writing with the mode as append instead of overwrite and then write every single word into it.



Hope it helps you mate.
 
salvin francis
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pavithra murthy
i didnt knw you are a girl,
some one sent me a pm and i realised that

sorry to call you "mate"

[ UD: non-English part removed ]
 
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

salvin francis wrote:
[ UD: non-English part removed ]


Please note that JavaRanch is an English-only forum. Please do not write in languages other than English, otherwise a moderator might delete your post.
 
reply
    Bookmark Topic Watch Topic
  • New Topic