I'm trying to write a small program in java, that'll calculate surface are and volume of a sphere, based on the radius of the sphere. These radii comes from .txt file with a single column of numbers.
I've tried searching a bit for this: Reading numbers in java
The code example looks a bit complicated for me as I'm not yet comfortable and experienced in reading java code. I've also tried reading this one:
Opening and reading numbers from a text file
I get confused of the 'try' keyword, among other things, what is it there for?
Where the second example says File("file.txt");
Do I put in the path to my text file?
If anyone can point me to a tutorial that'll take a beginner through these things, I'd very much like to know.
Here is my code so far:
import java.io.*;
// This class reads a text file (.txt) containing a single column of numbers
public class ReadFile {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String fileName = "/home/jacob/Java Exercises/Radii.txt";
Scanner sc = new Scanner(fileName);
}
}
Best regards,
Jacob Collstrup