?
Solved

how to read and write from a text file?

Posted on 2003-03-16
6
Medium Priority
?
164 Views
Last Modified: 2010-03-31
can you help me?
after readin some tutorial i still have got no idea.
thx
0
Comment
Question by:teiz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 8

Expert Comment

by:akshayxx
ID: 8149139
show your attempt at coding
0
 
LVL 6

Accepted Solution

by:
expertmb earned 150 total points
ID: 8149289
Hi,
 this will help.

//read file
    try{
      inFile = new FileInputStream(new File("abc.txt"));
      LineNumberInputStream inLines = new LineNumberInputStream(inFile);
      DataInputStream inStream = new DataInputStream(inLines);
      String inputLine;
      while ((inputLine=inStream.readLine()) != null) {
     //save it to some collection for later use
      }
    } catch(Exception oex){
     //error
    }

//write to file
  try{
      Object oaValues = getValues();//some method which return array of objects
      FileOutputStream outFile = new FileOutputStream("abc.txt");
      for(int iIndex = 0; iIndex < oaValues.length; iIndex++){
        byte b[] = (oaValues[iIndex].toString() + "\n").getBytes();
        for(int i = 0; i < b.length; i++)
          outFile.write(b[i]);
      }
    } catch(Exception oex){
     //error
    }


mb...
0
 

Author Comment

by:teiz
ID: 8149949
thank u expertmb
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

Author Comment

by:teiz
ID: 8150068
thank u expertmb
0
 
LVL 6

Expert Comment

by:expertmb
ID: 8150607
if ur requirement is met, then plz accept it as answer.
0
 
LVL 1

Expert Comment

by:shji1
ID: 8151268
Just dont forget to flush and close when you write a file(i.e. outFile.flush() and outFile.close()).
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question