Joern
06-25-2007, 12:28 AM
Hello hello
I have written a code to read a local csv-file:
/* CsvRead.java */
import java.io.*;
public class CsvRead
{
public static void main( String[] args )
{
try
{
File csvFile = new File( "test.csv" );
FileReader fileReader = new FileReader( csvFile );
BufferedReader reader = new BufferedReader( fileReader );
String line = null;
String columns[];
int i = 0, j = 0;
while (( line = reader.readLine()) != null )
{
columns = line.split( ";" );
if ( i < 20 )
{
for ( j = 0; j < 2 && j < columns.length; j++ )
{
System.out.print( columns[ j ] + "\t" );
}
System.out.println();
}
i++;
}
reader.close();
}
catch( Exception ex )
{
ex.printStackTrace();
}
}
}
this works fine, if I'm put this in an application und run it with:
>java CsvRead
But if I put the same code in the init() part of an applet, the code doesn't work: The last statement of the try-block which is executed is:
File csvFile = new File( "test.csv" );
May be this behaviour is related to the security of java-applets but my code is local (not on a webserver).
If this is right, what do I have to do to make it work in the applet, and is it possible after uploading the applet to a webserver to read a csv-file which is located on the webserver?
Joern
I have written a code to read a local csv-file:
/* CsvRead.java */
import java.io.*;
public class CsvRead
{
public static void main( String[] args )
{
try
{
File csvFile = new File( "test.csv" );
FileReader fileReader = new FileReader( csvFile );
BufferedReader reader = new BufferedReader( fileReader );
String line = null;
String columns[];
int i = 0, j = 0;
while (( line = reader.readLine()) != null )
{
columns = line.split( ";" );
if ( i < 20 )
{
for ( j = 0; j < 2 && j < columns.length; j++ )
{
System.out.print( columns[ j ] + "\t" );
}
System.out.println();
}
i++;
}
reader.close();
}
catch( Exception ex )
{
ex.printStackTrace();
}
}
}
this works fine, if I'm put this in an application und run it with:
>java CsvRead
But if I put the same code in the init() part of an applet, the code doesn't work: The last statement of the try-block which is executed is:
File csvFile = new File( "test.csv" );
May be this behaviour is related to the security of java-applets but my code is local (not on a webserver).
If this is right, what do I have to do to make it work in the applet, and is it possible after uploading the applet to a webserver to read a csv-file which is located on the webserver?
Joern