Results 1 to 4 of 4

Thread: Scanner & PrintStream Issue in Java

  1. #1
    Join Date
    Apr 2010
    Posts
    90

    Scanner & PrintStream Issue in Java

    I have recently started learning about the Scanner & PrintStream in Java. I have done some basic programs of Java but still I am not able to sort out my problem of Scanner & PrintStream in Java. I have a small problem from import java.util.Scanner. I conduct tests to learn to read the files .txt and for that I use "Scanner". I am using the
    Code:
    Scan file = new Scanner (new File ("Test.txt"));
    So please help me to sort out my problem. Provide some more information about the Scanner & PrintStream that are used in Java.

  2. #2
    Join Date
    Jan 2006
    Posts
    211

    Re: Scanner & PrintStream Issue in Java

    Input source: an existing file test.txt ""
    File scanner = new Scanner (new File ("test.txt '));

    Code:
    import java.util.Scanner; 
    import java.io. *; 
    word analysis class file 
    (Public static void main (String [] args) throws IOException 
    (String line; 
    File scanner = new Scanner (new File ("WortanalyseDatei.java")); 
    while (datei.hasNextLine ()) 
    Datei.nextLine (line = (); 
    Scanner s = new Scanner row (); 
    int i = 1; 
    while (s.hasNext ()) 
    System.out.println ("part" + (i + +) + ":" + s.next ()); 
    System.out.println ("======"); 
    ) 
    ) 
    )

  3. #3
    Join Date
    Jan 2009
    Posts
    140

    Re: Scanner & PrintStream Issue in Java

    Instead of the predefined file object System.out be new file objects (Class File) created and the constructor of PrintStream class as the output destination specified. Instead of output to the screen, opening a file for output
    PrintStream output = new PrintStream (new File ("Test.txt"));
    and print this file with the usual functions
    output. println (...);
    Important: In the end, closing the output file with test.close ();

  4. #4
    Join Date
    Dec 2008
    Posts
    202

    Re: Scanner & PrintStream Issue in Java

    Class methods define functionality that is independent of object attributes for all objects of the class is useful. A class method can not access the object!! Example in the class Circle:
    Code:
    class Circle 
    (... 
    static private double noOfCircles = 0; 
    Circle (double ix, double iy, double ir) 
    ( 
    x = ix, y = iy; radius = is; 
    noOfCircles + +; 
    ) 
    static double getNumberOfCircles () (return noOfCircles;) 
    ... 
    void move (double dx, double dy) (... ) 
    void grow (double ds) (... ) 
    void draw (Turtle Frame t) ... ( ) 
    )

Similar Threads

  1. Java barcode scanner
    By Rily in forum Software Development
    Replies: 6
    Last Post: 28-07-2010, 10:33 AM
  2. Java - scanner package for user input
    By Shaan12 in forum Software Development
    Replies: 4
    Last Post: 21-07-2010, 02:49 PM
  3. How to add parse in scanner in java?
    By MAGAR in forum Software Development
    Replies: 5
    Last Post: 02-03-2010, 04:30 PM
  4. Scanner can't read in java
    By cyber-noob in forum Software Development
    Replies: 3
    Last Post: 14-11-2009, 12:42 PM
  5. Scanner problems (java)
    By Zidaan in forum Software Development
    Replies: 2
    Last Post: 25-11-2008, 05:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,622,599.17965 seconds with 17 queries