import java.awt.*;
import java.applet.*;
import java.io.*;
import java.net.*;

public class localFileRead extends Applet {

public void init()
{
	setBackground(new Color(255, 240, 200));
}

public void paint(Graphics g)
{
	try
	{
		boolean macOS = (System.getProperty("os.name").startsWith("Mac"));
		boolean windowsOS = (System.getProperty("os.name").startsWith("Win"));
		String userHome = System.getProperty("user.home");
		BufferedInputStream bis = null;	
		URL rootOnClientURL = null;
		if (macOS) rootOnClientURL = new URL("file", "", "//" + System.getProperty("user.home") + "/");
		else if (windowsOS) rootOnClientURL = new URL("file:/" + userHome.replace('\\', '/')  + "/AppData/LocalLow/");
		g.drawString("rootOnClientURL = " + rootOnClientURL, 10, 30);
		URL url = new URL(rootOnClientURL, "localFile.txt");
		bis = new BufferedInputStream(url.openStream(), 32768);
		DataInputStream dataIS = new DataInputStream(bis);
		String s = dataIS.readUTF();
		dataIS.close();
		bis.close();
		g.drawString("Reading a local file worked.  Its contents are = " + s, 10, 60);
	}
	catch (Exception e)
	{
		g.drawString("Reading a local file didn't work.  The Exception is: " + e.getMessage(), 10, 70);
	} 
}
}  // END OF Class localFileRead

