Hello everyone,
I'm working on an assignment that requires the use of the Scanner class to read the source code of the .java file and output all lines when executed. I have created a file that works without issues on my machine, but I was wondering if there was a more robust way to reference the file location. Currently, the code has a static file location that is only true for my system, and I would like it to function regardless of the drive or directory. Any references or ideas are appreciated.
//************************************************************************************************************************************************************************
//Assignment for Module 3: Assignment3.java
//Dan
//U#
//September 16th, 2012
//Quine -Java program designed to utilize Scanner class to read source code and then display code to user at execution; no input is required of user.
//************************************************************************************************************************************************************************
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
public class Assignment3 {
public static void main(String[] args) throws FileNotFoundException {
Scanner inFile = new Scanner(new FileReader("C:/Users/Danimal/Documents/Fall 2012/EEL4854 IT Data Structures/src/Assignment3.java"));
while (inFile.hasNextLine())
System.out.println(inFile.nextLine());
}
}