can not find the file
in
Programming Questions
•
3 years ago
Hi ,
I am try to read a text file and when I want run the program it giving me an error unable to find the file
here is my code . I put the text file in the same sketch folder and the program also can not find it .
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.ArrayList;
//ArrayList<TableRecord> listTableRecords;
void setup()
{
size(100,100);
ArrayList <TableRecord> listTableRecords = new ArrayList<TableRecord>( );
try
{
FileReader fr = new FileReader("experiment2.txt");
// FileReader ft=new FileReader("tofile.txt");
BufferedReader br = new BufferedReader( fr );
// declare String variable and prime the read
String stringRead = br.readLine( );
while( stringRead != null ) // end of the file?
{
// process the line read
StringTokenizer st = new StringTokenizer( stringRead, "," );
String scene = st.nextToken( );
String condition = st.nextToken( );
String img_name = st.nextToken( );
try
{
TableRecord frTemp = new TableRecord(scene, condition,img_name);
// add FlightRecord obj to listFlightRecords
listTableRecords.add( frTemp );
}
catch( NumberFormatException nfe )
{
System.out.println( "Error in flight record: "
+ stringRead
+ "; record ignored" );
}
// read the next line
stringRead = br.readLine( );
}
// release resources associated with "flights.txt"
br.close( );
}
catch( FileNotFoundException fnfe )
{
System.out.println( "Unable to find experiment2.txt" );
}
catch( IOException ioe )
{
ioe.printStackTrace( );
}
// print the TableRecords read
for ( TableRecord table : listTableRecords )
System.out.println( table );
}
I am try to read a text file and when I want run the program it giving me an error unable to find the file
here is my code . I put the text file in the same sketch folder and the program also can not find it .
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.ArrayList;
//ArrayList<TableRecord> listTableRecords;
void setup()
{
size(100,100);
ArrayList <TableRecord> listTableRecords = new ArrayList<TableRecord>( );
try
{
FileReader fr = new FileReader("experiment2.txt");
// FileReader ft=new FileReader("tofile.txt");
BufferedReader br = new BufferedReader( fr );
// declare String variable and prime the read
String stringRead = br.readLine( );
while( stringRead != null ) // end of the file?
{
// process the line read
StringTokenizer st = new StringTokenizer( stringRead, "," );
String scene = st.nextToken( );
String condition = st.nextToken( );
String img_name = st.nextToken( );
try
{
TableRecord frTemp = new TableRecord(scene, condition,img_name);
// add FlightRecord obj to listFlightRecords
listTableRecords.add( frTemp );
}
catch( NumberFormatException nfe )
{
System.out.println( "Error in flight record: "
+ stringRead
+ "; record ignored" );
}
// read the next line
stringRead = br.readLine( );
}
// release resources associated with "flights.txt"
br.close( );
}
catch( FileNotFoundException fnfe )
{
System.out.println( "Unable to find experiment2.txt" );
}
catch( IOException ioe )
{
ioe.printStackTrace( );
}
// print the TableRecords read
for ( TableRecord table : listTableRecords )
System.out.println( table );
}
1