Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-16-2008, 10:39 PM
Member
 
Join Date: Nov 2008
Posts: 3
coolFrenzi is on a distinguished road
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
Sponsored Links
  #2 (permalink)  
Old 11-17-2008, 01:33 AM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 356
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
What have you done so far?show us your code
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-17-2008, 05:33 AM
Member
 
Join Date: Nov 2008
Posts: 3
coolFrenzi is on a distinguished road
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-18-2008, 12:45 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 533
fishtoprecords is on a distinguished road
Quote:
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
Sponsored Links
Reply


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

vB 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 02:11 PM
how do you write applets in Eclipse shashgo Eclipse 0 09-07-2008 01:48 AM
File read/write problems p900128 New To Java 4 06-27-2008 02:15 AM
Read/Find Substring/Write to new file hiklior New To Java 6 04-23-2008 04:47 AM
files and applets, please help willemjav Java Applets 0 02-08-2008 12:27 AM


All times are GMT +3. The time now is 09:35 AM.


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