Using following program you will able to know how to add parse in scanner. It is very simple code. In the following code I have use java.io.FileReader class which read input from the user and write something on other file. I also have use java.io.FileWriter class which include all input and out methods.
Code:
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String args[]) throws IOException {
int k;
double ds;
boolean bs;
String strs;
String strs1;
String strs2;
String strs3;
String strs4;
String strs5;
FileWriter fouts = new FileWriter("cars.txt");
fout.write("if int as = 30 int cs = as / 5 ;");
fouts.close();
FileReader fins = new FileReader("cars.txt");
Scanner srcs = new Scanner(fins);
while (srcs.hasNext()) {
if (srcs.hasNextInt()) {
k = srcs.nextInt();
System.out.println("int: " + k);
} else if (src.hasNextDouble()) {
ds = srcs.nextDouble();
System.out.println("double: " + ds);
Bookmarks