September 04, 2010, 04:00:14 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  Home Help Media Affiliates Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Read a file using BufferedReader & FileReader  (Read 10925 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2620
Referrals: 13

WWW Awards
« on: August 26, 2007, 07:45:31 PM »

Code
GeSHi (java):
  1. import java.io.BufferedReader;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. /*--------------------------------------------------------------------------
  6. //Author List:
  7. //   deAppel <Creator>
  8. //
  9. //Description:
  10. // Read a file on disk and output it in the console.
  11. //
  12. //Environment:
  13. //   This software was developed using Eclipse and Java 1.6
  14. //
  15. //Copyright Information:
  16. //   Copyright (C) 2007      <Institution><None>
  17. // Ark de Appel www.engineeringserver.com
  18. //
  19. //----------------------------------------------------------------------*/
  20. public class ReadFile {
  21.  
  22.  
  23. public static void main(String[] args) {
  24. ReadFile rf = new ReadFile();
  25. rf.ReadFile();
  26. }
  27.  
  28. public void ReadFile(){
  29. try {
  30. FileReader fr = new FileReader("c:\\test.txt"); // read a file
  31. String tmp;
  32. tmp = br.readLine(); // read first line of file.
  33.  
  34. while(tmp != null){ // read a line until end of file.
  35. System.out.println("" + tmp); // system out before tmp = br.readLine();
  36. tmp = br.readLine();
  37. }
  38.  
  39. br.close();
  40.  
  41. } catch (FileNotFoundException e) {
  42. // TODO Auto-generated catch block
  43. e.printStackTrace();
  44. } catch (IOException e) {
  45. // TODO Auto-generated catch block
  46. e.printStackTrace();
  47. }
  48. }
  49.  
  50. }
  51.  
  52.  
Created by GeSHI 1.0.7.20
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Javaforums.net :: a community about Java software development.
« on: August 26, 2007, 07:45:31 PM »

 Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here
Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Valid XHTML 1.0! Valid CSS!
Page created in 0.267 seconds with 34 queries.

Google visited last this page Today at 02:27:39 AM