Question
1. public static void read (String inFile, String [] lines){ try { Scanner read = new Scanner (new File (inFile)); lines = new String[read.nextInt()]; for
1.
public static void read (String inFile, String [] lines){
try {
Scanner read = new Scanner (new File ("inFile"));
lines = new String[read.nextInt()];
for (int i = 0; i < lines.length; i++) {
lines[i] = read.nextLine();
} } catch (IOException e){
System.out.println("can't read: " + inFile);
System.exit(-1); } }
public static void main (String [] args){
String [] lines = null; read ("in.txt", lines);
System.out.println(Arrays.toString(lines)); }
inFile:
3 Hey!
Hows it going?
Fun Stuff
The answer is: can't read: in.txt
I want to know,why ?
I think it should be [Hey!, Hows it going?, Fun Stuff]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started