I am having a lot of trouble getting this program to work properly. No compilation errors, but this is the output i get when i compile;
init:
deps-jar:
Compiling 1 source file to /home/alias120/NetBeansProjects/createFile/build/classes
compile:
run:
Checking to see if file already exists...
true
You produced the following file contents: null
BUILD SUCCESSFUL (total time: 1 second)
Here is the code, I am trying to read the contents of the file and output it to the user. Any suggestions would be great, been racking my brain with this.
public class Main {
public static void main(String[] args) throws Exception {
File inputFile = new File("/home/alias120/Desktop/School/CMIS 141/Project 4/input.txt");
System.out.println("Checking to see if file already exists...");
System.out.println(inputFile.exists());
PrintWriter output = new PrintWriter(inputFile);
output.print("We came, ");
output.print("we saw, ");
output.print("we conquered.");
Input myInput = new Input();
System.out.println("You produced the following file contents: "
+ myInput.readData);
}
}
class Input{
String readData;
Input() throws Exception {
File inputFile = new File("/home/alias120/Desktop/School/CMIS 141/Project 4/input.txt");
Scanner input = new Scanner(inputFile);
while(input.hasNext()){
String s1 = input.next();
String s2 = input.next();
String s3 = input.next();
readData = s1 + s2 + s3;
input.close();
}
}
}