Article View: borland.public.jbuilder.java.api
Article #366Re: How can I change data in a file?
From: Adrian Pitulac
Date: Thu, 09 Oct 2003 01:06
Date: Thu, 09 Oct 2003 01:06
65 lines
2402 bytes
2402 bytes
here is a way of reading your data:
"
String tip = null;
try
{
BufferedReader br = new BufferedReader(new FileReader("test.txt"));
String str = null;
while((str = br.readLine()) != null)
{
if (str.startsWith("LB ="))
{
tip = str.substring(4); //removes the 'LB = '
tip = tip.trim(); // tip is your values
}
}
}
catch(Exception ioe)
{
...................................
}
after that you have the values from your file
you can change them and then recreate your file based on the new values
with something like this:
"
File file1 = new File("text.txt");
FileOutputStream file = new FileOutputStream("text.txt",true);
DataOutputStream out = new DataOutputStream(file);
out.writeBytes(txt); //txt is the content of your file
out.flush();
"
also you'll have to include java.io.*
there are many other ways of dealing with your problem.
i hope i was helpful to you
bye
"Eun" <gte521w@prism.gatech.edu> wrote in message
news:3f8c6a8e$1@newsgroups.borland.com...
> Hi.
>
> I have a file "test.txt" with data below;
> --------------------
> LB = 0.1500000
>
> OPP = 30.00000
>
> MAX = 40.00000
>
> ------------------------------
>
> I want to change the numbers and save the file.
>
> Can anyone please let me know what I should do?
>
> Thanks.
>
>
>
>
Technical Details
Message-ID:
<3f8c9d73@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3f8c6a8e$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,8cb841adb87efb60 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2003-10-14 18:09:10 PST From: "Adrian Pitulac" <apitulac@pcnet.ro> Newsgroups: borland.public.jbuilder.java.api References: <3f8c6a8e$1@newsgroups.borland.com> Subject: Re: How can I change data in a file? Date: Thu, 9 Oct 2003 04:06:03 +0300 Lines: 67 Organization: InterData Systems 2000 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 213.154.130.123 Message-ID: <3f8c9d73@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1066179955 213.154.130.123 (14 Oct 2003 18:05:55 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail