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.
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 ("======");
)
)
)
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 ();
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) ... ( )
)