Napisałem programik ... i działa.
Fragment otwierający plik wygląda tak:
if(fc.showOpenDialog(this)==JFileChooser.APPROVE_OPTION)
{
File f=fc.getSelectedFile();
if(f.exists())
{
String file=f.getAbsolutePath();
try
{
url=new URL("file:"+file);
}
catch (Exception e)
{
say(e.getMessage());
}
if(src==open)
{
try
{
ep.setPage(url);
}
catch (Exception e)
{
say(e.getMessage());
}
}
else
{
String s=My.readFromFile(file,this);
ep.setText(s);
}
setTitle(file);
try
{
ep.setDocument((HTMLDocument)ep.getDocument());
}
catch(Exception e)
{
say("<html>Plik <font color=\"blue\">"+file+"</font> <br>nie jest plikiem
HTML</html>");
}
}
}
Funkcja czytająca plik tekstowy (z klasy My) wygląda tak:
public static String readFromFile(String file,Container c)
{
StringBuffer txt=new StringBuffer();
try
{
BufferedReader in=new BufferedReader (new FileReader(file));
while (in.ready())
{
txt.append(in.readLine()+"\n");
}
in.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(c,e.getMessage(),"",JOptionPane.INFORMATION_MESSAGE);
}
return txt.toString();
}