Search for more details......

Finding vars in java source file using java

You can write a program that search for given variable types. This is example program for searching double float and int Variables. You can change the logic of if statement which are written with sCurrentLine.contains("float") like statements.





import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class TraceVarsInSource {

    public static void main(String[] args) {

        BufferedReader br = null;

       

        try {

            String sCurrentLine;
//Set the source file.
            br = new BufferedReader(new FileReader("D:\\workspace\\Secure_Packager\\src\\sun\\security\\Sun_Secure_Packager.java"));

            while ((sCurrentLine = br.readLine()) != null) {

//Check for var types.                              if(sCurrentLine.contains("double")||sCurrentLine.contains("float")||sCurrentLine.contains("int")){                                     String []data=sCurrentLine.split("=");
                                     if(data.length>1)
                                     System.out.println("Found Variable:"+data[0].trim()+"\tValue:"+data[1]);
                              }
               
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null)br.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }

    }
}

No comments:

Post a Comment