-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokenClass.java
More file actions
44 lines (42 loc) · 1.62 KB
/
TokenClass.java
File metadata and controls
44 lines (42 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package Framework;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class TokenClass {
public static void main(String[] args) throws IOException {
String data = "Course=Machine Learning;Platform=Coursera;Instructor=Andrew NG;University=Stanford University";
//Hard coded String data
int c = 0;
StringTokenizer ST = new StringTokenizer(data);
while(ST.hasMoreTokens()) {
System.out.println(ST.nextToken("=; "));
c++;
}
System.out.println("Number of Words in data: "+c);
FileInputStream FIS = new FileInputStream("C:\\MyJava\\MyML.txt");
byte[] b = new byte[FIS.available()];
FIS.read(b);
int count = 0;
// Taking String data from a text file
String fileData = new String(b);
StringTokenizer STF = new StringTokenizer(fileData);
while(STF.hasMoreTokens()) {
System.out.println(STF.nextToken("\n"));
count++;
}
System.out.println("Number of Lines in MyML.txt: "+count);
FileInputStream FIS1= new FileInputStream("C:\\MyJava\\Number.txt");
byte[] BA = new byte[FIS1.available()];
FIS1.read(BA);
// Taking String data from a text file
ArrayList<Integer> AL = new ArrayList<>();
String fileData1 = new String(BA);
StringTokenizer STF1 = new StringTokenizer(fileData1);
while(STF1.hasMoreTokens()) {
String N = (STF1.nextToken(","));
AL.add(Integer.valueOf(N));
}
System.out.println(AL);
}
}