Naturally you can't use a FileInputStream
for this, FileInputStream
is for reading files, and you can't access the local file system in an unsigned applet. Your resources are available over the net, not as files. If your applet is signed, the code you've quoted will look for the "details.txt" file in the user's current working directory in their file system, not necessarily the directory containing the class file.
You can load resources from within the jar the applet class is in using Class#getResource
to get a URL
you can open, or using Class#getResourceAsStream
to do it all in one. So for instance, this code within an instance method within an applet will open an InputStream
to the "details.txt" file in the same directory in the jar as the applet class
file:
InputStream is = getClass().getResourceAsStream("details.txt");
I know that works for resources within the jar. Whether it works for other resources on the same codebase I couldn't say, I always bundle everything into the jar. See also this related question (and its answers).
So two steps: Put the file in the jar, and use the code above to retrieve its contents.