Results 1 to 3 of 3
Thread: Problems with CsvRead
- 07-04-2007, 05:35 AM #1
Member
- Join Date
- Jun 2007
- Posts
- 95
- Rep Power
- 0
Problems with CsvRead
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:
May be this behaviour is related to the security of java-applets but my code is local (not on a webserver).Java Code:File csvFile = new File( "test.csv" );
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?
code to read a local csv-file:
ThanksJava Code:/* 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(); } } }
Felissa:p
- 07-04-2007, 05:38 AM #2
Member
- Join Date
- Jun 2007
- Posts
- 91
- Rep Power
- 0
Since Java is ran on the local machine is it basically impossible to read directly from the webserver (or at least, without "hacking" it). On possible way is showcased here:
java applet read/write
The basics are this:
Put the file on the webserver
read it from the url
and go about your merry way.
At least, this is what I would do.
I wanted to add, aren't csv files seperated with a , and not a ; ?
Wiki CSV
Greetings
Daniel:o
- 07-04-2007, 05:40 AM #3
Senior Member
- Join Date
- Jun 2007
- Posts
- 114
- Rep Power
- 0
Your java application executes on your machine, and thus reads the file with no problems.
Applets are different, however, because they execute in the clients browser.
So, when you try to access the file through the applet, it is actually trying to look onto your clients machine, and for security reasons, this can't be done without using a secured applet. Daniel's solution will work fine, as it makes the file available on the internet, and thus available to the applet.
Greetings
Albert:rolleyes:
Similar Threads
-
Problems in JSP : Need help
By raj4u in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 02-07-2008, 10:06 AM -
GUI problems.
By saytri in forum New To JavaReplies: 1Last Post: 12-16-2007, 10:27 PM -
gui problems
By bluebirdjc in forum Advanced JavaReplies: 2Last Post: 07-23-2007, 05:38 PM -
a few problems
By gary in forum AWT / SwingReplies: 0Last Post: 07-11-2007, 04:57 PM -
problems with JPA
By Ed in forum New To JavaReplies: 2Last Post: 07-04-2007, 05:34 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks