Hello, I have pretty much completed this assignment and coded everything right, just for the completion it cant end on a new empty line and I can not figure out how to not have it.
My code:
import java.io.FileNotFoundException;
import java.io.File;
import java.io.PrintWriter;
import java.util.Scanner;
public class FunWithFiles {
/**
* Displays the file given by fname to the screen
*
* @param fname file to be displayed
*/
public static void displayFile(String fileName) {
try {
File bFile = new File(fileName);
Scanner fscnr = new Scanner(bFile);
while(fscnr.hasNextLine()) {
if(fscnr.hasNextLine()) {
System.out.println(fscnr.nextLine());
}
}
fscnr.close();
} catch (FileNotFoundException e) {
System.out.println("ERROR - File " + fileName + " not found!");
}
}
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
System.out.print("Enter a filename: ");
String fileName = scnr.nextLine();
displayFile(fileName);
scnr.close();
}
}

