Passing method as argument
Hi all,
I would like to modify a txt file (replace chars and delete) but I don't know how to use the return from a method into another method.
This is the sample txt file
Code:
07/21/2009;09:03;2009-07-21 09:03:00.000;6,10;6,135;6,075;6,095;16234
07/21/2009;09:03;2009-07-21 09:03:00.000;6,10;6,135;6,075;6,095;16234
07/21/2009;09:03;2009-07-21 09:03:00.000;6,10;6,135;6,075;6,095;16234
and this is the method to read this file, store and return a String variable name line
Code:
public String readTxtFile()throws IOException{
String line="";
try{
FileReader fr = new FileReader("C:\\myfile.txt");
BufferedReader br = new BufferedReader(fr);
System.out.println("Contents in file:\n");
while((line=br.readLine())!=null){
System.out.println(line);
}
fr.close();
br.close();
}
catch(FileNotFoundException fnf){
System.out.println("File not found!");
}
return line;
}
What I have now is a string line that I want to convert using this method
Code:
public String conversion(){
//String prova =("C:\\myfile.txt");
String result="";
StringBuilder remove = new StringBuilder();
result=(remove.delete(16, 40).toString());
result=result.replace(',','.');
result=result.replace(';',',');
result= result.replace("09:03","0900");
System.out.println(result);
return result;
}
Both these methods are in a class named -Methods-
Now my questions are:
1) how can I do to get the line return from first method and pass into the conversion method?
Should I pass it as argument such as
StringBuilder remove = new StringBuilder(readTxtFile()); ?
2)I want to call these method in Main class, name -ConvertMain-, and for this reason I create an object name test .
Code:
public static void main(String[] args) throws IOException {
Methods test = new Methods();
test.readTxtFile();
}
If a call the readTxtFile method it all works fine, but how to call the second method in main class?
Thank you very much!
Susie