September 04, 2010, 01:54:46 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: How to Read File in Java using the Scanner class  (Read 1233 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: July 26, 2008, 09:11:01 AM »

An example i wrote to show you to read a file in java using the Scanner class

Code
GeSHi (java):
  1. Scanner version:
  2.  
  3. public class ReadLineDemo {
  4. public static void main(String[] args){
  5. ReadLineDemo EDS = new ReadLineDemo();
  6. EDS.readFile();
  7. }
  8. public void readFile(){
  9. String str;
  10. try {
  11. fr = new FileReader(”c:\\input.txt);
  12. System.out.println(”begin”);
  13. Scanner sc = new Scanner(fr);
  14. while(sc.hasNext()){
  15. str = sc.nextLine();
  16. System.out.println(str);
  17. }
  18. }
  19. e.printStackTrace();
  20. }
  21. }
  22. }
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: July 26, 2008, 09:11:01 AM »

 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.194 seconds with 32 queries.

Google visited last this page September 02, 2010, 11:04:25 PM