Results 1 to 4 of 4
- 11-16-2008, 08:39 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 11
- Rep Power
- 0
[SOLVED] Read/write files using applets
I have written an application in java which reads files as input and writes to a file as output.
All the input/output files are at server side. The user just needs to select a file from menu. The result is displayed in a text area.
I want to display this application on my webpage. Converting the application to applet is not working since applets can't read from and and write to a file.
Any ideas about how this can be done? (I really don't have any idea of JSP or servlets.)
Thanks in advance.
- 11-16-2008, 11:33 PM #2
What have you done so far?show us your code
- 11-17-2008, 03:33 AM #3
Member
- Join Date
- Nov 2008
- Posts
- 11
- Rep Power
- 0
the sample applet with error when read/write a file
Here is a sample code with the same error (java.security.accessControlException: access denied) when running as an applet.
The code reads an input file, writes the content to an output file, and then reads the output file and displays the content in an Area box in the applet.
/*<applet code="text.class" width=500 height=500> </applet> */
Please let me know how I can implement this. I have gone through a few web pages but I haven't been able to solve it.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JApplet;
import java.io.*;
import java.io.IOException;
public class text extends JApplet
{
JLabel TextLabel1;
JComboBox Combo1;
TextArea Area1;
JScrollPane Scroller1;
BufferedReader in;
BufferedWriter out;
String read, iFile1;
public void init()
{
resize(800, 600);
TextLabel1 = new JLabel("Select an Input file");
Area1=new TextArea(10,50);
Scroller1=new JScrollPane(Area1);
Combo1=new JComboBox();
Combo1.addItem("red");
Combo1.addItem("green");
Combo1.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
String s = (String)Combo1.getSelectedItem();
perform(s);
}
});
setLayout(new BorderLayout());
JPanel pane1 = new JPanel();
pane1.add(TextLabel1);
pane1.add(Combo1);
pane1.add(Area1);
add(pane1, BorderLayout.NORTH);
setVisible(true);
}//end of init
void perform(String st)
{
iFile1=st;
try
{
in = new BufferedReader(new FileReader(iFile1));
out = new BufferedWriter(new FileWriter("out.txt"));
while(in.ready())
{
read = in.readLine();
out.write(read);
out.newLine();//write a new line to the file
}
in.close();
out.close();//flushes and closes the stream
in = new BufferedReader(new FileReader("out.txt"));
while(in.ready())
{
read = in.readLine();
Area1.append(read + "\n");
}
in.close();
}
catch(IOException e)
{
System.out.println("There was a problem:" + e);
}
}
}
- 11-17-2008, 10:45 PM #4
That is a feature of applets. The solution is to not use applets.
If you are doing browser stuff, have the browser read/write the files.
You probably need to learn about servlets, which are server side, not client-side the way applets are.
Programming in the browser should be done in javascript, not in java
Similar Threads
-
Read and Write file
By mrdestroy in forum New To JavaReplies: 13Last Post: 10-31-2008, 12:11 PM -
how do you write applets in Eclipse
By shashgo in forum EclipseReplies: 0Last Post: 09-06-2008, 11:48 PM -
File read/write problems
By p900128 in forum New To JavaReplies: 4Last Post: 06-27-2008, 12:15 AM -
Read/Find Substring/Write to new file
By hiklior in forum New To JavaReplies: 6Last Post: 04-23-2008, 02:47 AM -
files and applets, please help
By willemjav in forum Java AppletsReplies: 0Last Post: 02-07-2008, 10:27 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks