|
hi. i am new to jsp programming and i'm facing some problems with the codings. i wonder how to change those java codes into jsp. is it possible to open the text file and insert it into <textarea>? thanks in advance...
void doOpenCommand () {
String curFile;
char[] data;
String fred;
FileDialog file = new FileDialog
(frame, "Open File", FileDialog.LOAD);
file.setFile ("/forum/.java.txt");
file.show();
if ((curFile = file.getFile()) != null) {
String filename = file.getDirectory() + curFile;
frame.setCursor (Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
File f = new File (filename);
try {
FileReader fin = new FileReader (f);
int filesize = (int)f.length();
data = new char[filesize];
fin.read (data, 0, filesize);
fred = new String(data);
System.out.println (fred);
pane.setText("");
pane.append (fred);
status.setText ("Loaded: " + filename);
}
catch (FileNotFoundException exc) {
status.setText ("File Not Found: " + filename);
} catch (IOException exc) {
status.setText ("IOException: " + filename);
}
}
}
void doSaveCommand(){
String curFile;
char[] data;
FileDialog file = new FileDialog
(frame, "Save File", FileDialog.SAVE);
file.show() ;
if ((curFile = file.getFile()) != null) {
String filename = file.getDirectory() + curFile+ "1";
File f = new File (filename);
try {
FileWriter fw = new FileWriter (f);
String text = pane.getText();
int textsize = text.length();
fw.write(text,0,textsize);
fw.close();
status.setText ("Saved: " + filename);
} catch (IOException exc) {
status.setText ("IOException: " + filename);
}
}
}
|
|
|
|
|
|
|
|