Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-16-2008, 08:39 PM
Member
 
Join Date: Nov 2008
Posts: 11
Rep Power: 0
coolFrenzi is on a distinguished road
Default [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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-16-2008, 11:33 PM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 451
Rep Power: 2
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
Default
What have you done so far?show us your code
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-17-2008, 03:33 AM
Member
 
Join Date: Nov 2008
Posts: 11
Rep Power: 0
coolFrenzi is on a distinguished road
Default 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);
}

}

}
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-17-2008, 10:45 PM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 571
Rep Power: 2
fishtoprecords is on a distinguished road
Default
Originally Posted by coolFrenzi View Post
Converting the application to applet is not working since applets can't read from and and write to a file.
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
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read and Write file mrdestroy New To Java 13 10-31-2008 12:11 PM
how do you write applets in Eclipse shashgo Eclipse 0 09-06-2008 11:48 PM
File read/write problems p900128 New To Java 4 06-27-2008 12:15 AM
Read/Find Substring/Write to new file hiklior New To Java 6 04-23-2008 02:47 AM
files and applets, please help willemjav Java Applets 0 02-07-2008 10:27 PM


All times are GMT +2. The time now is 03:42 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org