Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how to read and write from a text file?

Posted on 2003-03-16
6
Medium Priority
?
165 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
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
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!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month15 days, 23 hours left to enroll

580 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