Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

io problem

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ranchers,
i have one problem with , i want to read one file , the contents of the file is like this,
file name: 1.txt
name age date of birth
x 21 82
y 23 80
i want to read the file then i, want to manipulate age like 21+3 and want to write in new file 2.txt after manipulation.
please help me
thanks
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I'm sorry i just had a few minutes and i could complete u'r pprogram by hardcoding the value of the character position ..u could use a while or for loop for this instead, when u use io it reads character by character so u should add add digit wise
hope this helps ..u should be able to fine tune this program i'm givin below for u'r use
import java.io.*;
import java.util.*;
public class readwrite
{
public static void main(String[] ar)
{
try
{
// initailize buffer reader
BufferedReader in = new BufferedReader(new FileReader("1.txt"));
//initialize buffer writer
BufferedWriter out = new BufferedWriter(new FileWriter("2.txt"));

String str;
String str1;
//read from file 1.txt
while((str=in.readLine())!=null)
{

//return ascii value for char at position 3
int tt=((int)str.charAt(3)+4);
//cast to chatr and get the value from ascii
char c=(char)tt;
//replace string with the specific value
str1=str.replace(str.charAt(3),c);
//write into 2.txt
out.write(str1);
}

in.close();
out.close();
}
catch(IOException e)
{

}

}
}
 
today's feeble attempt to support the empire
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic