• Post Reply Bookmark Topic Watch Topic
  • New Topic

To add commas in file using java  RSS feed

 
Gokul Raam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

This is my first question in this forum...
I have file with numeros datas(both numeric and characters) in a file
I want to delimit the file with set of delimiter length like 2,5,1,9,6 etc..

For example
if my file like this
9483trdcvge245621jde

then i need to insert commas at 2,5,1,9,6 etc..
then the output will be
94,83trd,c,vge245621,jde,

Like this i need..Please help me to solve this issue..
Thanks in advance
 
Sunil Kumar
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
text files doesnt support text editing.
It is actually an abstract concept that there are lines in a file.
Text file is actually a collection of char with carriage returns. Hence, a BufferedWriter can only append strings to file. So you will need to read the file in java, modify it, delete the old file and then save it back to the system.

So Open a file reader > Read the whole file content in a String[] object or a Vector > close the file reader > change the lines in this String[] object > open a filewriter with append as false > write the content into this filewriter > close the filewriter.
[ December 29, 2008: Message edited by: Sunil Kumar ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!