Reading files in a Java applet.

Discussion in 'Science, Technology & Car Chat' started by khaotic, Dec 2, 2007.

  1. khaotic

    khaotic Fobulous

    Sorry if the mods consider this Off Topic, but I'm really desperate right now. i have this program due tomorrow which reads from a txt file to receive information on certain shapes and then draws them. I've got most of it worked out except for reading the actual file. Unlike past assignments I've done, this needs to be within an applet. Since I can't throw IOExceptions in applet methods I don't know how I'm suppose to read the file. All I know is that it involves some work with try-catch, which I'm not really knowledgeable with O_O. Anyone willing to help me? Please! :(
     
  2. BigSmoke

    BigSmoke Well-Known Member

    66
    31
    0
    Can you elaborate it more?? ^_^
     
  3. kontradictions

    kontradictions Well-Known Member

    Can you please post the code? I'm learning Java myself and I could probably help you if I saw the code. Did you remember to throw exceptions in the method declaration where you read from a text file?

    EDIT: I just read it over, since you cant throw exceptions, have you tried the using the try and catch pair method?

    try
    {
    [attempt to read from file here]
    }

    catch( IOException ex)
    {
    [display an error message of some sort to tell the user the file could not be read]
    }
     
  4. BigSmoke

    BigSmoke Well-Known Member

    66
    31
    0
    I don't know if this will help you, but If you want to read your files in a Java Applet. Try reading this.

    http://www.captain.at/programming/java/ its too long, and I don't know if this will help you.
     
  5. kontradictions

    kontradictions Well-Known Member

    Try this and see if it works.

    Code:
    try
    {
      java.io.File file = new java.io.File("text file");
      *read data from the file*
    }
    catch(IOException ex)
    { 
      *error message here*
    }
    
    EDIT: Even if you don't want to display an error message, you must include catch.