Solved

Writing to file using Applet Problem

Posted on 2002-04-06
9
248 Views
Last Modified: 2010-03-31
I managed to read a text file from the host where the applet originates using a URL, Now,I need to write to it again. How do I do it.
Here is code I used to read from the textfile. I used a vector to read from it to a List box.
Thanx...

public void readWords()
     {
     //get path to data from parameter..
     String dataPath = getParameter("categfile");
     if (dataPath ==null){
          System.out.println("No data variable found");
          return;
     }
     URL dtex;
     try{
     dtex =new URL(getDocumentBase(),dataPath);
     }
     catch (MalformedURLException e) {
     System.out.println("Bad data URL");
     return;
     }
         
     try {
         
          URLConnection d =dtex.openConnection();
         
          BufferedReader word = new BufferedReader(new InputStreamReader(d.getInputStream()));

     
//for(int i=0; i>2; i++)
     while ((inputLine = word.readLine()) != null){
     System.out.println(inputLine);
     wordVec.addElement(inputLine);
     }
     word.close();
     }
catch (MalformedURLException e){//new URL() failed
     System.out.println("No data variable eeeeee found");
     
     return;
}
catch (IOException e){//openConnection() failed

 System.out.println("No data variablefffff found");

     return;
     }
}
0
Comment
Question by:q_bic
9 Comments
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 6924265
You can't write to a file on the server.
You need something on the server that you can post the file to, such as a servlet.
0
 
LVL 3

Expert Comment

by:rjackman
ID: 6924648
I think u can
Use the same procedure and get the outputstream for writing to file
then u have to give the permission to the applet for writing to file for that u have to create the policy file that give the prmission to applet for writting to file and place it in to directory from where u are running the applet for more info pls refer the following site

pls refer to Question No: 4
http://java.sun.com/sfaq/#read

for giving permission refer to following

refer point No2

http://java.sun.com/docs/books/tutorial/security1.2/tour1/index.html

cheers
RJ
0
 
LVL 92

Expert Comment

by:objects
ID: 6924652
> Use the same procedure and get the outputstream for writing to file

And what is that output stream going to connect to on the server?
0
 
LVL 92

Expert Comment

by:objects
ID: 6924655
> pls refer to Question No: 4

That refers to writing files on the client, not the server.
As does the second link.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 5

Expert Comment

by:LexZEUS
ID: 6925278
>I think u can Use the same procedure and get the outputstream for writing to file

I don't think so.. it will cause big security hole, if it is doable, then I want to create java application to read and modify Microsoft.com's main page (index.html) .. :)
0
 
LVL 5

Expert Comment

by:LexZEUS
ID: 6925287
use ftp utility to upload the file...

http://sourceforge.net/projects/j-ftp/
http://www.enterprisedt.com/downloads/ftp.html
http://www.kcmultimedia.com/jftp/download.html

as long as you upload/download the file to the same internet domain, I think ftp will works fine in applet (no security exception)...
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6956635
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20282927.html
http://www.experts-exchange.com/questions/Q.20285583.html
http://www.experts-exchange.com/questions/Q.20286912.html
http://www.experts-exchange.com/questions/Q.20286982.html




*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations if this item remains inactive another seven (7) days.  If you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed here -> http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7933392
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: objects
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7984201
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now