Results 1 to 2 of 2
  1. #1
    cachi is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default Read a string from a txt file

    Hi, I want to read a string from a txt file.
    The program returns error at run time from the Java's security class.
    Java Code:
    try {
    FileInputStream fis = new FileInputStream("README.TXT");
    int n;
    while ((n = fis.available()) > 0) {
    byte[] b = new byte[n];
    int result = fis.read(b);
    if (result == -1) break;
    String s = new String(b);
    System.out.print(s);
    } // End while
    } // End try
    catch (IOException e) {System.err.println(e);}
    System.out.println();
    Thanks.

  2. #2
    silvia is offline Member
    Join Date
    Jul 2007
    Posts
    35
    Rep Power
    0

    Default

    Applet's don't have permission to read files from the client computer. You can either include the file in the jar of the applet, and then load the file using ClassLoader's getResource... methods. Or you can put the file on the same server as the jar, and then access it remotely (I'm not too familiar with J2SE but I think you create a Url object or something).

Similar Threads

  1. Is there a way to read a file directory
    By willemjav in forum Java Applets
    Replies: 3
    Last Post: 09-05-2011, 01:01 AM
  2. help to read .pst file through java
    By umadas in forum Advanced Java
    Replies: 2
    Last Post: 12-19-2010, 04:32 AM
  3. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:13 AM
  4. Read file
    By tajinvillage in forum Threads and Synchronization
    Replies: 0
    Last Post: 01-29-2008, 09:10 AM
  5. read txt file
    By sureshsri1981 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-05-2007, 03:49 PM

Posting Permissions

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