Java Testing class

import java.io.*;

public class test {

 public static void main(String[] args) {

   String str = "";
   try {
     BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
     System.out.print( "> ");
     str = in.readLine();
   } catch (IOException e) {

   } // finished reading console input
   try {
     BufferedWriter out = new BufferedWriter(new FileWriter("test.txt"));
     out.write(str);
     out.close();
   } catch (IOException e) {
   } // finished writing to a file

   System.out.println("Reading the file and printing .... ");
   try {
     BufferedReader in = new BufferedReader(new FileReader("test.txt"));
     String s;
     while ((s = in.readLine()) != null) {
       System.out.println(s);
     }
     in.close();
   } catch (IOException e){ 
 } // finished reading the file and printing to std out
 }
}

See also
Modulus and OpEquals Example
Changing Fahrenheit to Centigrade
Class BRReadLines
Testing class

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.