I have a data structure assignment were the code has to read the text data from a text file and print it onto the screen. The code that I wrote says that the build was a success but the text file itself doesn't print. What do I do?
import java.util.Scanner; import java.io.IOException; import java.io.FileInputStream public class readFile{ public static void main(String[] args) throws IOException { FileInputStream fileByteStream = null; Scanner file = null; int textFile; try{ fileByteStream = new FileInputStream("file1.txt"); file = new Scanner(fileByteStream); while(file.hasNextInt()){ textFile = file.nextInt(); System.out.println("file1.txt"); } } catch(IOException e){ } } }
Replace System.out.println("file1.txt"); by System.out.println(textFile);.
System.out.println("file1.txt");
System.out.println(textFile);
1.4m articles
1.4m replys
5 comments
56.9k users