
Hi i am new to java and i am trying to build lexecal analyser for java code , I am in the beginning want to read the file then tokanize it, so i wrote this code that read line from the buufer , put it in string then put the tokens into array of string ,but after run the code it gives" error:null" plz kindly could any of you tell me what is wrong in it . also i want to use the tokenizer class but i don't know how to use it,realy i would be thankful if you kindly help me in this . print("import java.io.*; import java.util.Scanner;
class FileRead{
@SuppressWarnings("null") public static void main(String args[]) {
try{
FileInputStream fstream = new FileInputStream("always.java");
new BufferedReader(new InputStreamReader(fstream));
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine = " ";
String tokens[] = null ;
int i=0;
//Read File Line By Line
Scanner input = new Scanner( strLine );
while ( (strLine =br.readLine()) != null) {
//StringTokenizer st =new StringTokenizer(fstream);
//System.out.println (strLine);
while(( tokens[i]=input.next())!= null){
System.out.println (tokens[i]);
i++;
}}
//Close the input stream
// in.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage());
} }}
");

import java.io.*;
import java.util.*;
class FileRead{
public static void main(String args[]) {
try{
File f=new File("FileRead.java");
BufferedReader br = new BufferedReader(new FileReader(f));
String strLine = " ";
String filedata="";
while ( (strLine =br.readLine()) != null) {
filedata+=strLine+" ";
}
StringTokenizer stk=new StringTokenizer(filedata);
while(stk.hasMoreTokens()){
String token=stk.nextToken();
System.out.println(token);
}
br.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.