how to connect a non static method into void main(String[] args)

privatestaticfinal String DELIM =",";

/**

* Compile two files.

*

* @param file1 String the input file 1

* @param file2 String the input file 2

* @param file3 String the output file

* @throws IOException error in reading/writing

*/

publicvoid compareFiles(String file1, String file2, String file3)throws

IOException{

BufferedReader reader1 =new BufferedReader(new InputStreamReader(

new FileInputStream(file1)));

BufferedReader reader2 =new BufferedReader(new InputStreamReader(

new FileInputStream(file2)));

BufferedWriter writer =new BufferedWriter(new OutputStreamWriter(

new FileOutputStream(file3)));

String line1 = reader1.readLine();

String line2 = reader2.readLine();

while (line1 !=null && line2 !=null){

writer.write(compareLines(line1, line2));

writer.newLine();

line1 = reader1.readLine();

line2 = reader2.readLine();

}

reader1.close();

reader2.close();

writer.close();

}

private String compareLines(String line1, String line2){

StringTokenizer tok1 =new StringTokenizer(line1, DELIM);

StringTokenizer tok2 =new StringTokenizer(line2, DELIM);

String name = tok1.nextToken();

String number = tok1.nextToken();

String scheme = tok1.nextToken();

// ignore number

tok2.nextToken();

String date = tok2.nextToken();

String value = tok2.nextToken();

StringBuffer buffer =new StringBuffer();

buffer.append(name);

buffer.append(DELIM);

buffer.append(number);

buffer.append(DELIM);

buffer.append(date);

buffer.append(DELIM);

buffer.append(scheme);

buffer.append(DELIM);

buffer.append(value);

return buffer.toString();

}

may i know how do i can connect this non static method intopublicstaticvoid main(String[] args)

?

[3075 byte] By [wilfrid100a] at [2007-10-3 3:19:59]
# 1

public class Test{

//your methods

public static void main (String args[]){

new Test().compareFiles();

}

}

Seeing that you dont use any instance variables in your methods, its better to keep the methods static. Then you dont have to create an instance to access the methods.

public class Test{

public static void compareFiles(.......................){.......}

public static void main (String args[]){

compareFiles();

}

}

or in a main method of some other class

public class Main{

public static void main (String args[]){

Test.compareFiles();

}

}

ram.

Madathil_Prasada at 2007-7-14 21:12:03 > top of Java-index,Java Essentials,New To Java...