We have a group project to get data from a text file that will be input by the user. We have created a method to get the input and get the data saved to a output file but I'm stuck as to how we will get the file to be read for the methods we create that will then read through the file. Currently it just prints to the console.
public static void main(String[] args) throws FileNotFoundException {
Scanner in = new Scanner(new File("dna.txt")); //create scanner object for dna.txt
processFile(in);//call the method using scanner as parameter
File outputFile = new File("DataOutput.txt");
PrintStream fileOutput = new PrintStream(outputFile);
fileOutput.close();
}
public static void processFile(Scanner in) throws FileNotFoundException{
Scanner console = new Scanner(System.in);//open Scanner in the console
System.out.println("File to be read: ");//prompt user to enter the txt file
String inputFile = console.next();//turns file into string and read in console
while (in.hasNextLine()){//while stuff is in file, keep looping
String s = in.nextLine();//contents in file = string s. we can now process s with arrays
System.out.println(s);//print s
}
}
}