In: Computer Science
Hi
I have problem with run this JAVA file
import java.io.*;
public class DataPresenter {
public static void main (String args []) {
System.out.println("File:../SmallAreaIncomePovertyEstData.text");
System.out.println("Id" + "\t" + "Population" + "\t" +
"ChildPop"
+ "\t" + "CPovPop" + "\t" + "CPovPop%");
}// read the data
try (FileReader fr = new FileReader("File:
C:\\605.201/SmallAreaIncomePovertyEstData.text"))
{
int c;
while (( c = fr.read())!= -1){
System.out.print((char) c);
}
}
catch(IOException e) {
System.out.println("I/O Error" + e);
}
}
Please help to fix
Please let me know if anything is required.
Copyable code :
import java.io.*;
public class DataPresenter {
public static void main (String args []) {
System.out.println("File:../SmallAreaIncomePovertyEstData.text");
System.out.println("Id" + "\t" + "Population" + "\t" +
"ChildPop"
+ "\t" + "CPovPop" + "\t" + "CPovPop%");
try //try block for opening the file
{
//creating file reader object
//replace your full path of file here
FileReader fr = new
FileReader("SmallAreaIncomePovertyEstData.txt");//("File:
C:\\605.201/SmallAreaIncomePovertyEstData.text");
int c;
while (( c = fr.read())!= -1){ //reading the contents of the
file
System.out.print((char) c); //printing the contents of the file to
the console
}
}
catch(IOException e) { // catch block for the file opening, if file
nit exist then it will throw the error
System.out.println("I/O Error" + e);
}
}
}
Sample input:
Sample output 1:
Sample output2:
Duwuy T op Main.java SmallArealncome... : 1 1 20 10 2 3 2 2 34 5 7 3 3 3 43 5 6 7 4 4 5 6 7 8 U + WNA 5 |
File: ../SmallAreaIncome PovertyEstData.text Id Population ChildPop CPOVPop CPovPop: 1/0 Errorjava.io.FileNotFoundException: input (No such file or directory)
Id File: ../ SmallAreaIncome PovertyEstData.text Population ChildPop CPovPop CPOVPop/ 1 20 10 2 3 2 34 5 7 3 3 43 5 6 7 4 5 6 7 8