tokenizing a java file
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());
}
}}
");
View Answers
May 30, 2011 at 12:55 PM
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());
}
}
}
Related Tutorials/Questions & Answers:
tokenizing a java file tokenizing a
java file 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... = " ";
String tokens[] = null ;
int i=0;
//Read
File Line By Line
Scanner input
Advertisements
Convert Class File to .java File - Java BeginnersConvert Class
File to .
java File Sir, How To Convert .class
file to .
java File.
Please Help me Use cavaj software ,which is freeware, to convert .class to .java Use jd-gui to convert ur .class to .
java file in java - Java Beginnersfile in java I want to count the number of white line and comment line in a
file (.sql) with
java
if you have an example
thank you in advance
Java File - Java BeginnersJava File Hi Friend,
Thank you for the support I got previously...
Anyone please send me the
Java Code for scanning a directory and print....
Output
Print the
file names and size of the
file to the console.
Please
Reading a text file in java in java.io.* package for reading and writing to a
file in
Java.
To learn more about reading text
file in
Java see the tutorial Read
File in
Java.
Thanks...Reading a text
file in java What is the code for Reading a text
file How to rename a file in Java?How to rename a
file in
Java? Hi,
What is the code for renaming a
file?
How to rename a
file in
Java?
Thanks
Hi,
You can use... the
File or Directory in
Java.
Thanks
Batch file for java applicationBatch
file for
java application please tell me how to create the batch
file for
java application(using swings).the application is created with netbeans
java read filejava read file Hello i need some help...
i want to read an MS Excel
file in
java so how to read that
file Java write to fileJava write to file How to write to a
file in
Java?
Is there any good example code here?
Thanks
Hi,
Java is one of the best... Handling examples in
Java
Java Input/Output Examples
How to read
file in
Java How to write in File in JavaHow to write in
File in Java Hi,
How to write in
File in
Java. Please suggest and give example of this program.
thanks
Java class fileJava class file How do i open a
java class
file using eclipse
File handling in Java handling in
Java?
ThanksADS_TO_REPLACE_1
Hi,
File handling... such as .properties
file or xml
file.
Java programming language also... more at
File Handling in
Java.
Examples of
file handling in
Java:
Java Reading big file in JavaReading big
file in Java How to read a big text
file in
Java program?
Hi,
Read the complete tutorial at How to read big
file line by line in
java?
Thanks
Read file in javaRead
file in java Hi,
How to Read
file in
java?
Thanks
Hi,
Read complete tutorial with example at Read
file in
java.
Thanks
How to compress a file in Java?How to compress a
file in
Java? How to compress a
file in
Java through
Java code?
I want a good example in
Java.
Thanks
Hi,
Check the tutorial Compressing the
file into GZIP format.
Thanks
java file handlingjava file handling enter string from keyboard and then read a
file if this string is present in
file then print message already exists else write this string to
file Java lock file or folder.Java lock
file or folder. Is it possible to create a desktop application to lock or encrypt
file or folder in windows by using
java code??
if possible can provide some reference??
because i can't find it...
thanks
Download a file - Java BeginnersDownload a
file Hi,
I need a
java code to download a
file from a website and before downloading it should give me an option to browse and select the location to put the
file.
Thanks in advance
Java I\O fileJava I\O file What is the difference between the
File and RandomAccessFile classes
java file handlingjava file handling program to get values from textbox array and the write them to text files
Java file byte readerJava file byte reader I am looking for an example program in
Java for reading the bytes. More specifically I need
java file byte reader example code.
Thanks
For complete details read the following tutorials:
Java Java read binary fileJava read binary file I want
Java read binary
file example code... at Reading binary
file into byte array in
Java.
Thanks
Hi,
There is many more examples at
Java File - Learn how to handle files in
Java with Examples
Read from file javaRead from
file java How to Read from
file java? What is the best method for a text
file having a size of 10GB. Since i have to process the
file one line at a time so tell me the very best method.
Thank you
Java upload file to ftpJava upload
file to ftp Hi,
How to uploaded
file to a ftp server in
Java?
Thanks
Hi,
It's very easy to write a program in
Java....
View complete example at FTP
File Upload in
Java
Thanks
Java delete file if existsJava delete
file if exists Hi,
Hi how to delete
file if exists?
I need example code of
java delete
file if exists.
Thanks
Hi... if tempFile exists
File fileTemp = new
File(tempFile);
if (fileTemp.exists
base64 encode a file javabase64 encode a
file java Hi,
I want to convert the content of a
file into Base64 encoded string. I am using
Java 8 and i need the
Java program for base64 encoding a
file java.
What is the code for base64 encoding a
file java How to write in File in JavaHow to write in
File in Java Hi,
How to write in
File in
Java... to write in
File of
Java Program...,
For writing some data in the
file we require some class
file, objects
Executale File - Java BeginnersExecutale File Plz tell me how to convert
java file into .exe
file... the instruction.. Good Luck i don;t know how to create the exe
file for
java ... for
java but you can create an executable jar
file .create a MF
file How to Write to file in Java?How to Write to
file in
Java? How to Write to
file in
Java Program?
Hi,
For writing a
file in
Java, we need some classes from Java.IO package. Mostly we define two types of classes in
java file i.e. FileWriter
xml file creation in javaxml
file creation in java how to create xml
file in
java so that input should not be given from keyboard. and that
file should be stored.
Please visit the following links:
http://www.roseindia.net/tutorial/
java/xml
IO File - Java BeginnersIO File Write a
java program which will read an input
file & will produce an output
file which will extract errors & warnings.
It shall exclude... from the log
file.
This is the task assigned to me..Please help me
jar file - Java Beginners an application packaged as a JAR
file (requires the Main-class manifest header)
java -jar...jar file jar
file When creating a jar
file it requires a manifest
file. what is the manifest
file, and how to create it. And tell me more about
Java File Management ExampleJava File Management Example Hi,
Is there any ready made API in
Java for creating and updating data into text
file? How a programmer can write code for reading the text
file?
What is best way to read a text
file in
Java Playing mp3 file in Java...Playing mp3
file in
Java... I created frame with play and stop buttons and added separate ActionListener to those buttons but i can't stop the music while playing
File Handling in JavaFile Handling in Java Hi,
While opening a
file in
Java developers... was trying to find some tutorials about handling
file in
Java on net. I have also seen... of
file.
Java also cares about the performance of the application. It provides
java file handlingjava file handling Hi friends,
My situation is i have
file named "sample.conf" which contains more IP Adressess.Eg: the
file contains "IP=255.255.255.255" at some lines in the
file. what i need to do is. i need to search
copy file - Java Beginners File("C:\\Answers\\Master.txt"),new
File("c:\\
java\\Master.txt...copy file i want to copy
file from one folder to another
... CopyFile{
public void copy(
File src,
File dst) throws IOException
file handling - Java Beginners manner.
now write a progam in
java and create another
file which is having the amount required to purchase each item and at last read the newly created
file...
file handling assume two files are there- 1. with the quanity of he
core java-filecore
java-file hi,
i want to create a
file name simple.txt using command promt and also i want to insert a 36 numbers in a
file using command prompt only and then i want to make that data in the form two data in a bracket lke
Excel file Handling in JavaExcel
file Handling in Java Hello Sir,
I am new to
Java, I have Started
Java Core by myself. I want to make a project which include 3-4 Excel
file...://www.roseindia.net/tutorial/
java/poi/readExcelFile.html
Now to create an excel
file Setup file - Java BeginnersSetup file Hello sir ,how i can make
Java Programs Set up
File.... Point to note here is that the
Java compiler very well knows about...:
http://www.roseindia.net/
java/exceptions/how-to-throw-exceptions.shtml
File Handling - Java BeginnersFile Handling
Q. Write a
java prg which accepts a list of existing text files from command line args & concatinate contents of all files...(e.getMessage());
}
}
}
its prg of copying
file Check code