Hi ,all
in this code ,i read filename in package filename using path ,,now i want to read the file B.java that also exist in package filename and relationship between them is inhretance.. "extends" keyword.
in this (public class filename extends B ),
but not write B.java in path ,i want to read any file after extends keyword in program filename.
can anyone help me.
i mean i want to read any file.java that come after extends keyword.

 public class  CyclomaticComplexity{
  public static void main(String[] args) {
 try {
 fileName = "C:\\NetBeansProjects\\filename\\src\\filename\\filename.java");

  FileReader fr = new FileReader(fileName);
  BufferedReader br = new BufferedReader(fr);
  line = br.readLine();

            while (line != null) {
            line = br.readLine(); 
        }
        }
        catch (IOException e) {
         e.printStackTrace();

         }}   }
     //////////////////////////////
     ///filename program is
     public class filename extends B
{public static void main(String[] args) {
     int s=9;
     s=s+1;
     }......

Thank you very much ,but i want to do this manually!...

Since you know how to open files, that's not the issue.

You know the "B" is not a file but a class so that's a dead end, isn't it? And if you have a filename, you do a bit of string work to add the .java to get its name.

Your code above does not really reveal the files used by the app, does it?

But B is B.java and its exist in package filename ..so I want to open and read any file or class after extends keyword ..because also the B extends A class and also I want to read content of it and write it in an empty file....

Read every line in classes that come after extends keyword to write all contents in an one file can I do this?
thank you very much

Yes ...B is class ..so if I want to access to content of it when I reading filename.java .how can I do this because I want to count every inherited classes in this program(count how many coupling classes related with each other using extends keyword.....

So your quest is to find where the B class is, in what file. Then you read that file. Given I don't have your source code or the source of what's to be read, you need to find this manually first. It's something folk may call reverse engineering.

No..not exactly. .
I want to access all classes related to my filename.java ..
filename extends B
And in the B class , there is another class A ...so on ....
so
When I read file that contain extends (inheritance)...count how many coupling classes associated with that file ....in my code I need to find how many inherited classes for example. . Filename extends B. .
B extends A . ..so the coupling classes must be 2....

Since you just described how you manually counted, now put that into code. If you get stuck, break the problem down further.

Ok...tomorrow I will write my complete code because its complicated ..I will break it to make it easy to read and understood. ...
I hope you help me....thanks for you Mr. rproffitt.

package javaapplication12;
public class  CyclomaticComplexity {
 int o=4;
 private String p="m"; 
 public  int d(int s){

    if(s==9)

    return s;
    else 
        return(3);
 }


 public static void main(String[]argv) throws ClassFormatException, IOException {
        String w="ma";

String ext=null;
int l;
        int li=0;
        int complexity =0;   
        String fileName;
        String words="";      
        String line = null;
        int j=0,k=0;
        char c[]=new char[200];
         char[]cc=new char[20];
         int ee=0;
        int bb=0;
         int v=0;
         int mm=0;
         int b=0;
         int countfile=0;
                  int u=0;


String[] keywords= {"if","while", "case", "for", "&&","||", "?", ":", "catch"};
String[] ex= {"extends"};
int count=0;

        try {

            fileName = "C:/Documents/NetBeansProjects/filename/src/filename/filename.java";

            FileReader fr = new FileReader(fileName);
            BufferedReader br = new BufferedReader(fr);
             // il.size();
             line = br.readLine();           

            while (line != null) {
            for( int i=0;i<line.length();i++)
                 {            
                  b=line.indexOf("/",i);
                  ee=line.indexOf("*",i);
                    if(b!=-1 && ee!=-1)

                    v=line.indexOf("*/",i);
                      if (v==-1 )

                 line="";
                  }


              for(int i=0;i<line.length();i++)
                        { int nb = line.indexOf("/",i);

               if(nb==-1 )
                line=line.substring(nb+1); 
              else 
                  line=" ";
                        }



              StringTokenizer stTokenizer = new StringTokenizer(line,"( {");


             while (stTokenizer.hasMoreTokens()) {


              words = stTokenizer.nextToken();

             if (words.equals("extends"))
             {    u= line.indexOf("extends");


             words=line.substring(u+words.length());
             words=words+".java";
             ext=words.trim();
             }
              else 
             words =words;

                   System.out.println(words);






              for (int i = 0; i < keywords.length; i++) {

                  if(keywords[i].equals(words)) 
                       { complexity++;
                       }           
               }

             }  

          line = br.readLine(); 
        }
       System.out.println(" ");

        }
        catch (IOException e) {
         e.printStackTrace();
        }
        ///////////////////////////////////////
       //////open what come after extends keyword//
        try {

            String fileN = "C:/Users/Documents/NetBeansProjects/filename/src/filename/"+ext;

            FileReader fr = new FileReader(fileN);
            BufferedReader br = new BufferedReader(fr);
            // il.size();
            String lin = br.readLine();
            //System.out.println(br);        


            while (lin != null) {

                   System.out.println(lin);
                    lin = br.readLine(); 

        }
       lin = br.readLine(); 
        }
        catch (IOException e) {
         e.printStackTrace();

            }


         System.out.println();
         System.out.println("The cyclomatic copmplexity of the program is: "+(complexity+1));
         System.out.println("The coupling classes in the program are: "+(count));

         System.out.println("The whole cyclomatic copmplexity of the program with coupling classes is: "+(complexity+1+count));

         System.out.println("___________________________");
         System.out.println("The coupling classes in the program filename are: "+(countfile));
         System.out.println("The whole cyclomatic copmplexity of the program with coupling classes of filename is: "+(complexity+1+countfile));



         System.out.print("The cyclomatic complexity level is: ");
            if(complexity>=1 && complexity<=10 )
               System.out.println("Low risk program");
                  else
            if(complexity>=11 && complexity<=20 )
                System.out.println("Moderate risk"); 
                  else
             if(complexity>=21 && complexity<=50 )
                System.out.println("High risk");
                  else
            System.out.println("Most complex and highly unstable method ");  
       ////////////////////code of filenme program///
       package filename;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

public class filename extends A
{ 
public  int d(int s) 
    int mm;
{    if(s==9)
    return s;
 else
  return 0;
}
public static void main(String[] args) {
        filename ss=new filename();
     int s=9;
   int a=1,b=2,c=3;
    if(a>b) 
    {
         if(a>c && a==9)
              System.out.println(a);
              else
              System.out.println(c);
              }
              else
              if (b>c)
              System.out.println(b);
              else
              System.out.println(c);


    }}

    //////////////code of B file///
    package filename;

class B extends A {

     public void f2()
    {
        System.out.println("s2 ");
        //System.out.println("marwa");
    }

  public void getObject(){
              System.out.println("s6 ");

}
    ///////////////code of A file////
    package filename;

class A  {
public void f1() {

System.out.print ("s1");
}
}

Now ,,after i open B in try ...how can access to A,,,and how to copy the content of B to empty file ???

i want to copy content of B file or class to an empty file ??

If that's how your manual method works, then yes. One of the most powerful tools you have to to write down the steps you do to get the job done then code each step. It appears you know about java but falter when it comes to the design.

Not exactly Mr. rproffitt. ..I don't need to use any tool in my program ..I must try to programming manually ....
So..now I want one thing ...in try section in program how can I copy content (lines of file ) to an empty file (one file) from all files ....

If I google "how to copy a file in Java" I don't see any lack of answers. Your question leads me to think that either you don't use the web for research or you want folk to write code for you. Unsure what it is.

Back to my prior answer. You need to design your code first. Some folk try to code first and then get lost. Since you know how to do this manually, you break down each step into code, a function or a single line of code. Once you have all your steps in code, you have your solution.

Exactly ...Mr. rproffitt ... thank you very much for help me and thanks for your advice. ...

Mar. Na. If you have a function that doesn't work, think about breaking it down again. Remember an old school advice here. "Divide and conquer." If you have divided it but hit a snag, post that snippet and ask if folk can find Waldo (the bug.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.