Results 1 to 3 of 3
  1. #1
    Felissa is offline Member
    Join Date
    Jun 2007
    Posts
    95
    Rep Power
    0

    Default 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:
    Java Code:
    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?

    code to read a local csv-file:

    Java 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();
        }
      }
    }
    Thanks

    Felissa:p

  2. #2
    Daniel is offline Member
    Join Date
    Jun 2007
    Posts
    91
    Rep Power
    0

    Default

    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

  3. #3
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default

    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

  1. Problems in JSP : Need help
    By raj4u in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 02-07-2008, 11:06 AM
  2. GUI problems.
    By saytri in forum New To Java
    Replies: 1
    Last Post: 12-16-2007, 11:27 PM
  3. gui problems
    By bluebirdjc in forum Advanced Java
    Replies: 2
    Last Post: 07-23-2007, 06:38 PM
  4. a few problems
    By gary in forum AWT / Swing
    Replies: 0
    Last Post: 07-11-2007, 05:57 PM
  5. problems with JPA
    By Ed in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 06:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •