Home Answers Viewqa Java-Beginners tokenizing a java file

 
 


swarsarkos
tokenizing a java file
1 Answer(s)      2 years ago
Posted in : Java Beginners

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 Pages:
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
Tokenizing Delimiters
Java: Tokenizing Delimiters Purpose When tokenizing a string... from the String d Example: Tokenizing an expression Here is an example... run Java 2 applets correctly yet, so it's doubtful that you can see it working
File
File   How to find all files in our local computer using java
FILE
;Java Read content of File import java.io.*; public class Appliance { public...FILE  There is a file named Name.txt that contains information related to appliances.I want to read the contents of this file and I used the code
file
file  hi i want read special line of file. what am i doing ? I write a code but is false in this programm i want make tree with java but i should read data from file. please help me! void maketree(BtNode root,int i) throws
String file in to word file in java
String file in to word file in java  How to convert a String format notepad file into Ms word file in java
String file in to word file in java
String file in to word file in java  how to convert a String format word file into Ms Word file using java? please can anyone of you help me
calling a java file in java
calling a java file in java  how to call a another java file in java
file in java - Java Beginners
file 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 class
Java file class  What is the purpose of the File class
Convert Class File to .java File - Java Beginners
Convert 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
Java code to convert pdf file to word file
Java code to convert pdf file to word file  How to convert pdf file to word file using Java
Java File - Java Beginners
Java 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
java get file permission
java get file permission  How to check the get file permission in Java
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
Convesion of txt file to doc file.??????
Convesion of txt file to doc file.??????  how to convert text file to doc file using java
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java. Please suggest and give example of this program. thanks
Batch file for java application
Batch 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 file
java read file  Hello i need some help... i want to read an MS Excel file in java so how to read that file
java file handling
java 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
Reading big file in Java
Reading 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 java
Read file in java  Hi, How to Read file in java? Thanks   Hi, Read complete tutorial with example at Read file in java. Thanks
File handling in Java
handling in Java? Thanks   Hi, File handling is very important... such as .properties file or xml file. Java programming language also provide very good file handling features in their api. You can read more at File Handling in Java
Execute .dll file in java?
Execute .dll file in java?  please anybody give me solution for executing .dll files in java
Download a file - Java Beginners
Download 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 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
File Transfer
File Transfer  How to create a file in server side using java swing
Read from file java
Read 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
jar file
jar file  how to create a jar file in java
Java I\O file
Java I\O file  What is the difference between the File and RandomAccessFile classes
java file handling
java file handling  program to get values from textbox array and the write them to text files
Java file byte reader
Java 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
on file system
on file system  how to maintains record in a file using java and how to create objects to each record.   Hi, Please read Java Write file tutorial. Regards Deepak
Java delete file if exists
Java 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
How to write in File in Java
How 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
Java read binary file
Java 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
Executale File - Java Beginners
Executale 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
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
IO File - Java Beginners
IO 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
Java upload file to ftp
Java 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
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
JAR FILE
and applications. The Java Archive (JAR) file format enables to bundle multiple files into a single archive file. For more information, visit the following...JAR FILE  WHAT IS JAR FILE,EXPLAIN IN DETAIL?   A JAR file
File handlig
File handlig  File hyandling   Hi Please the click on the following link Java file Handling And read the Articles given in it   Hi Please the click on the following link Java file Handling And read
xml file creation in java
xml 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
java file handling
java 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
jar file
jar file  how to run a java file by making it a desktop icon i need complete procedur ..through cmd
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
Creating dynamic jsp file in java file to include another jsp file
Creating dynamic jsp file in java file to include another jsp file  I am able to create jsp file in java that includes ; table tr td and img tags..... Need to include jsp file in the same content. The below code doesn't help me
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

Ask Questions?

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.