How do I make this work?
Dear Zefria,
thank you for your suggestion. O miracle, it works (but only when used with a main method).
Not when I place the code in class: Solution_1.java and call this code from class: Use_solution_1.java (as you can see both are in the same package). Do you know how I make this work?
This is what I do:
Use_solution_1.java:
package solutions;
import java.io.*;
import solutions.Solution_1;
public class Use_solution_1
{
public void main(String[] args)
{
FileReadingMethod("c:\\temp\\this_will_never_work.txt");
}
}
Solution_1.java:
package solutions;
import java.io.*;
import static java.lang.System.out;
public class Solution_1 {
public void FileReadingMethod(String filename)
// public static void main(String args[])
{
BufferedReader br = null;
String line;
// String filename = "c:\\temp\\this_will_never_work.txt";
try
{
br = new BufferedReader(new FileReader(filename));
}
catch (FileNotFoundException e)
{
System.err.println("Requested file was not found!");
System.exit(1);
}
try
{
line = br.readLine();
while (true)
{
/////////
// PROCESSING CODES GOES HERE
/////////
out.println("Gelezen= "+line);
// Read the next line. If line==null, that indicates the end of the file.
line = br.readLine();
if (line == null) break;
}
}
catch (IOException e)
{
System.err.println("File was found, but an IOError occured!");
System.exit(2);
}
}
}
--------------= Posted using GrabIt =----------------
------= Binary Usenet downloading made easy =---------
-= Get GrabIt for free from http://www.shemes.com/ =-