🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.api
5 messages
5 total messages Started by Eun Tue, 14 Oct 2003 21:29
How can I change data in a file?
#365
Author: Eun
Date: Tue, 14 Oct 2003 21:29
17 lines
1092 bytes
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.
Re: How can I change data in a file?
#366
Author: Adrian Pitulac
Date: Thu, 09 Oct 2003 01:06
65 lines
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.
>
>
>
>
Re: How can I change data in a file?
#367
Author: Paul Furbacher TeamB
Date: Wed, 15 Oct 2003 04:22
33 lines
1810 bytes
In <3f8c6a8e$1@newsgroups.borland.com> Eun wrote:

>  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.

Adrian provided one way of solving your problem (see
parallel response).  

However, if you are open to changing the file extension
from .txt to .properties, you could use the java.util.Properties
class to handle this very easily.


Paul Furbacher [TeamB]

  Save time, search the archives:
       http://info.borland.com/newsgroups/ngsearch.html
       
  Is it in Joi Ellis's Faq-O-Matic? 
       http://www.visi.com/~gyles19/fom-serve/cache/1.html
 
  Finally, please send responses to the newsgroup only.
  That means, do not send email directly to me.
  Thank you.
Re: How can I change data in a file?
#368
Author: Valentino Kyriakides
Date: Wed, 15 Oct 2003 10:17
42 lines
2348 bytes
"Eun" <gte521w@prism.gatech.edu> schrieb im Newsbeitrag
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?
>

There are many different approaches available to handle this. Beside those
Adrian and Paul told you, you could for example read in and write out your
data also in a tab delimited format, as most spreadsheets and databases
would also support. Instead you could also write out and read in your data
in a well formed XML format etc. etc.

However, as Paul said, the easiest would really be to make use of Java's
Properties class to handle this and in case you don't like to have those
".properties" extensions, take one of those java based INI read/write file
examples and set it up in a way to work on your ".txt" extension. As an
example see:

http://www.codeguru.com/java/articles/655.shtml

http://www.geocities.com/Area51/9851/INIFiles.html

...and so on...

You can find a lot of similar and even more advanced such java based  INI
read/write examples on the internet.

-Valentino
Thanks a lot!
#369
Author: Eun
Date: Wed, 15 Oct 2003 17:28
4 lines
1026 bytes
I just got the job done.
Appreciate it.

- Eun
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads