// TestApplet.java
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.border.*;
public class TestApplet extends JApplet
implements ActionListener {
private JPanel pane = null;
private JScrollPane scrolling = null;
private JTextPane fileBox = null;
private JTextField tfFilename = null;
private JButton butLoad = null;
private final String LOAD = "load";
public void init() {
try {
jbInit();
} catch(Exception e) {
e.printStackTrace();
}
}
// method which will read data from file, and return it in
// String
public String readFile(String fn) {
String thisLine, ret = "";
try {
FileInputStream fin = new FileInputStream(fn);
BufferedReader myInput = new BufferedReader
(new InputStreamReader(fin));
while ((thisLine = myInput.readLine()) != null) {
ret += thisLine + "\n";
}
} catch (Exception e) {
ret = "Cannot load, exception!";
}
return ret;
}
private void jbInit() throws Exception {
pane = new JPanel();
pane.setBounds(new Rectangle(0, 0, 500, 325));
pane.setLayout(null);
pane.setBorder(BorderFactory.createEtchedBorder(
EtchedBorder.LOWERED));
pane.setBackground(new Color(221, 194, 219));
fileBox = new JTextPane();
fileBox.setText("");
fileBox.setEditable(false);
scrolling = new JScrollPane(fileBox);
scrolling.setBounds(new Rectangle(16, 65, 295, 225));
tfFilename = new JTextField();
tfFilename.setText("");
tfFilename.setBounds(new Rectangle(16, 23, 206, 29));
butLoad = new JButton();
butLoad.setBounds(new Rectangle(231, 23, 80, 30));
butLoad.setText("Load");
butLoad.setActionCommand(LOAD);
butLoad.addActionListener(this);
pane.add(scrolling);
pane.add(tfFilename);
pane.add(butLoad);
setContentPane(pane);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals(LOAD)) {
fileBox.setText(readFile(tfFilename.getText()));
}
}
}
//C:\Setup.log 절대경로로 파일 로드.
<html>
<head></head>
<body>
<applet code="TestApplet.class" archive="TestApplet.jar" width=325 height=325>
</applet>
</body>
</html>
익스플로러 에서 보안상 차단 한다.
해당 applet jar 파일을 Singed Applet으로 만들어 줘야 한다.
Windows 시작의 검색창에 configure.java로 검색하여 창을 연 후 보안탭의 보안 레벨을 "중간"으로 변경 해준다.
참고 : http://www.developer.com/java/ent/article.php/3303561/Creating-a-Trusted-Applet-with-Local-File-System-Access-Rights.htm