How to write file in Applet

I have a code:
URL url = new URL("http://hostname/file.txt");
URLConnection con = url.openConnection();
con.setDoOutput(true);
OutputStream out = con.getOutputStream();
String s = "Test";
byte[] b = s.getBytes();
out.write(b);
out.close();
But it does not create or save into file.
Please tell me how to solve it.
Thanks.
Nghianh

URL url = new URL("http://hostname:80/cgi");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();

Similar Messages

  • How to write file to server side?

    hello,
    Could anyone pls help me...
    I just want to see an example how can I write to a file that is placed at the server(save place as the applet).
    p.s. I have been successfully read a file from there...
    Suppose I have signed the applet (self-signed), anymore security problem I need to pay attention to?
    Thanks a lot!!

    hi mandy, from the applet u can send the file to be written into the server to a servlet running in server and the servlet can in turn write the file into the servlet. by applet - servlet communication, u can easily read and write files to the server.

  • How to write file at server end?

    Hi,
    I use a af:inputFile component to receive uploaded files. And want to write files to the directory of server. However, when execute java.io.File.createNewFile(), it throw exception. How to resolve it?
    import org.apache.myfaces.trinidad.model.UploadedFile;
    import javax.faces.event.ValueChangeEvent;
    import java.io.InputStream;
    import java.io.File;
    public class UploadFileHandler {
        public void doUpload(ValueChangeEvent event) throws IOException {
            File file = new File("C:\temp.txt");
            *file.createNewFile();* //Error happen here.
    }

    Hi Cheney,
    It is good practice to use System.getProperty("file.separator") instead of hardcoding "/" or "\" .
    Though your issue is resolved by using "//", you might want to consider changing to the above.
    -Arun

  • No permission to write files from applets

    Dear All,
    I wrote one applet for displaying a live video and able to capture a single frame and cine loops. It's working properly.
    Now i plug in this applet into my .jsp page. After this I'm facing so many problems.Initially i can't able to store anything
    from my applet (after plug in to .jsp). So i edit the java.policy file. Now i can store the single frames captured via my applet. But I'm not able to store the cine loops.
    _Following is my java.policy file contents,_
    grant codeBase "file:${{java.ext.dirs}}/*" {
         permission java.security.AllPermission;
    grant {
         permission java.lang.RuntimePermission "stopThread";     
         permission java.net.SocketPermission "localhost:1024-", "listen";
         permission java.util.PropertyPermission "java.version", "read";
         permission java.util.PropertyPermission "java.vendor", "read";
         permission java.util.PropertyPermission "java.vendor.url", "read";
         permission java.util.PropertyPermission "java.class.version", "read";
         permission java.util.PropertyPermission "os.name", "read";
         permission java.util.PropertyPermission "os.version", "read";
         permission java.util.PropertyPermission "os.arch", "read";
         permission java.util.PropertyPermission "file.separator", "read";
         permission java.util.PropertyPermission "path.separator", "read";
         permission java.util.PropertyPermission "line.separator", "read";
         permission java.util.PropertyPermission "java.specification.version", "read";
         permission java.util.PropertyPermission "java.specification.vendor", "read";
         permission java.util.PropertyPermission "java.specification.name", "read";
         permission java.util.PropertyPermission "java.vm.specification.version", "read";
         permission java.util.PropertyPermission "java.vm.specification.vendor", "read";
         permission java.util.PropertyPermission "java.vm.specification.name", "read";
         permission java.util.PropertyPermission "java.vm.version", "read";
         permission java.util.PropertyPermission "java.vm.vendor", "read";
         permission java.util.PropertyPermission "java.vm.name", "read";
         permission java.lang.RuntimePermission "accessClassInPackage.sun.jdbc.odbc";
         permission java.util.PropertyPermission "file.encoding", "read";
              <security>
         <all-permissions/>
         </security>
    grant codeBase "file:/D:/Raja/Java/MyProject/AppletEx/build/web/WEB-INF/classes/-" {
    permission java.io.FilePermission "<<ALL FILES>>", "read";
    permission java.io.FilePermission "<<ALL FILES>>", "write";
    I can also sing my applet (self certified). But the problem is not solved.
    In my log file i found the following is preventing to write the files.
    com.sun.media.JMFSecurityManager.checkFileSave(JMFSecurityManager.java:250)
    Can anyone help me to solve this issue..
    Regards
    ChennaiBee.

    To access files (read and write) from an applet, the applet needs to be signed.
    There is a forum here to discuss signed applets:
    http://forum.java.sun.com/forum.jspa?forumID=63
    These instructions (in Part III) for signing applets work:
    http://java.sun.com/javase/6/docs/technotes/guides/plugin/developer_guide/contents.html

  • How to write files to the filesystem with portal/plsql

    Hi,
    is there a way to write files to the filesystem via Portal?
    Or can i call an external programm (perl, php) to do so, while portal writes further information to database?
    thank you for the help
    Ralf Schmitt

    Hi Ralf,
    my primary task is to publish download-links to files stored ... somewhere as a linklist. I tried to store and download files to/from the database but i cant get it to run. Upload works, download doesn't.
    (i'm not talking about a single form-query-download-link! I need a report-like linklist)If you want to do this you'll have to write some code but sure it's possible - i did it myself.
    The links in the link list in your report should call a stored function retrieving the files from Wwdoc_document or whatever is the document table defined in your DAD. Simply select BLOB_CONTENT into a BLOB variable from the table, provided you know what file to read :-) The function would then read the BLOBs and send them to the client's browser via DBMS_LOB - it's poor design but it works just as smooth as it could and it's really performing. This would simply display the file into your browser or prompt for file save location, depending on what browser you are using and its client settings.
    I guess this is not so clear, if you want some more details feel free to e-mail me at [email protected]
    Another way would be to use wpg_docload to both download and upload files to/from the DB.
    Now i try to figure out if it is possible to store the files to the filesystem and write only additional info like description or path into db.Again, yes, it is. I can't recall exactly how I did it ^_^ but the trick is to create a virtual directory in the DB - pointing at a physical directory on the file system you want to write to, and you have to have full read-write permission on the directory itself, and its path must be included in the utl_file_dir database parameter. Then you use both COM Automation or UTL_FILE to write files.
    would it be possible to let a portal-form write info to the db and then pass the file to a php-script?
    regards,
    Ralf Schmitt

  • How to write files to phweb share drive(phweb is nonsap system)

    Hi all,
             Is there any way to write files directly to phweb share drive(phweb is Nonsap system).
    Thanks,
    Balalji

    Hi Rob,
               Yaa I got .But how to use that function modules and when to use.I heard that first we have to write to presenation server and then we can use one of those function modules.Is it right?
    Thanks,
    Balaji

  • How to  write file excel format xlsx/xlsb to pl/sql?

    Dear supporter,
    I built the xml report output excel file. However, the reported data and about 30 columns, line 200000 write and loading file slow, large file size
    How can write data directly to the format xlsb / xlsx from pl / sql. quickly and efficiently.
    Please, help me!
    Tks,
    Mr.T

    Check this thread.
    Re: 5. How do I read or write an Excel file?

  • How to write files on Client Machine using JSP

    Hi,
    I am new to JSP. Please tell me how do i write files on Client machine thru a Browser.
    Please let me know at the Earliest.
    Thanks.
    Mehul Dave

    1) Well I find it rather convenient to deploy a web app as just one file rather than a bunch of files. For deployment it's much better. However I prefer using expanded files when developping (to use auto reload in Tomcat for example)
    2) It is a bad idea to upload files inside your webapp's context (ie: in it's deployment directory) because one day an uninformed system administrator might come and redeploy the web app and therefore delete all your uploaded files (believe me, I've already experienced this!)
    What i do usually is upload it in a completely different directory, something like /uploaded_files. Your uploaded files are therefore completely independant from your webapp
    However it is a bit trickyer to get those files back. Let's take the example of image uploads. You have 2 ways of proceeding:
    - the easiest : configure your web server (apache etc...) to redirect a certain url to your external directory. For example the /upload url will point to a /uploaded_files directory. This is easier to do and the fastest way to serve images but not always the best solution: you are dependant on the web server's configuration and you can't control the visibility on your files (no security constraints, anyone can see your uploaded files if they know the url).
    - you can also write a servlet which will load the file as an array of bytes and send it back in the response.
    You can call it this way :
    <img src="/serlvets/showmyimage?path=uploaded.gif">
    in this way you can control your uploaded files better: you may want to define security constraints on the visibity or not of uploaded files depending on the user which has logged on the site.

  • How to write file to server using applet?

    Please help!!!!!!!!!!
    Why didn't this work?
    URLConnection ucon = url.openConnection();
                   ucon.connect();
                   ObjectOutputStream outStream = new ObjectOutputStream(new BufferedOutputStream(ucon.getOutputStream()));
                   outStream.writeObject(linkHolder);
                   outStream.close();
    .............As my applet run, the message printed out with my catch is: "java.net.UnknownSerivceException: Protocal doesn't support this output."
    However, the reading from server is fine:
    ObjectInputStream inStream = new ObjectInputStream(new BufferedInputStream(url.openStream()));
             links = (LinkHolder)inStream.readObject();
             inStream.close();
    ....I really appreciate for your help.
    JTom

    This file resides on server not local machine. I'm just testing on my local PC for now.
    By the way, applet doesn't allow any kind of communication to client machine or others, but only to the server it resides in; according to the specs.
    To get a url connection you need a server. You send
    the output to the server(some servlet or similar
    program running on server).
    But for file you don't need a server. You can open a
    file on your local machine if just have file
    permissions. There is no server involved here.

  • How creat flle and and how to write file network

    eg:\\bissstorage\Backups\sudhir
     i want to write inside ths folder...how to get path
    i tried this one 
    iFile = OpenFile ("\\bissstorage\\Backups\\sudhir\\TransducersDetails\\TransducersDetails.txt" , VAL_READ_WRITE, VAL_APPEND, VAL_ASCII); 
    but its not working im using cvi 5.5
    thank you
    Sudhir

    In a network pathname, some backslashes are doubled due to UNC naming rules: you must reflect this in your string, considering that each backslash character must be doubled to be used as is and not as an escape marking; that is, this string should work:
    iFile = OpenFile ("\\\\bissstorage\\Backups\\sudhir\\TransducersDetails\\TransducersDetails.txt" , VAL_READ_WRITE, VAL_APPEND, VAL_ASCII); 
    The same applies in case you want to build up the path with MakePathname: in this case you should do the following:
    char    file[512];
    MakePathname ("\\\\bissstorage", "Backups", file);
    MakePathname (file, "sudhir", file);
    MakePathname (file, "TransducersDetails", file);
    MakePathname (file, "TransducersDetails.txt" , file); 
    iFile = OpenFile (file , VAL_READ_WRITE, VAL_APPEND, VAL_ASCII); 
     

  • How to load files into applets?

    Hi,
    I have developed a quiz applet. The quiz applet will have a button by clicking which one can start quiz. The quiz will open in a Jframe.
    At first the frame shows screen to enter a username (no checking for present).
    After you click login it takes the test quiz file as input and number of questions to appear in quiz.
    After that quiz program will be reading the quiz file specified (available in the same directory), then parsing the file getting questions and answers into Objects of questionRecord.
    From these questionRecords a question will be given in the frame at random.
    Finally, score will be displayed to the user.
    The program works well when it is compiled in eclipse. When I try the same program to run in browser (I'm using Mozilla), I can't load the quiz file. I dont find any errors as it running in the browser. I dont understand where the problem might be.
    Here is the Url: http://csee.wvu.edu/~srikantv/Assign/Assignment4Applet1164649158249.html
    If you want to look at.
    Please help..
    Thanx

    You can configure the browser or the plugin so that the java console is displayed.
    Your problem is probably that an applet which isn't signed isn't allowed to read files from the local filesystem.
    Kaj

  • How to write file into multiple directories by using file adapter?

    i need to write my file into multiple directories,i able to do in single directory.But i need to write to muliple directories.Please help me out.Thanks in advance.

    If you are passing the values at runtime then you can loop it and and invoke the file adapter in loop by dynamically passing the value in invoke properties for "File Directory and File name" etc.

  • How to write file in user's local desktop

    Hi,
    Using the WriteFile action, i can write the file in inetpub/wwwroot in server.
    Is there any way to write the file in user's local drive folder?
    Although now i am writing the file to server and allowing the user to access it through URL but I suspect that there could be user concurrent issue or file contamination issue.
    Constraint - The file should open with the default name.
    If i try to open a local copy to the user (thru SaveasCSV() or URL)  and allow the user to save the copy then the default name appear as Illumniator.
    Regards,
    Anil

    I think your current approach of saving to the web location and providing the user access via URL is the best approach.  From a security standpoint I can't see that writing directly to a user's desktop/laptop would be a good idea.
    If you are worried about naming or concurrency issues, then create sub folders that match their user name, or devise a naming convention that allows the objects to be unique between users and purpose.

  • Write File in Applet

    I'm a student. I will be very happy if you could help!
    I'm writing an self-signed applet that runs on browser.
    Luckily there is no error shown in the java console when i run the applet.
    however, i can't store information to a file which is placed at the server(where my applet is placed).
    The biggest problem is there is NO ERROR message shown in the java console...
    everything seems running very well, except THE FILE IS NOT UPDATE!
    my source code for writing file:
    try{
    URL url1 = new URL("http://appletServer/~doris/1/User.properties");
    URLConnection con=url1.openConnection();
    con.setDoOutput(true);
    OutputStream out = con.getOutputStream();     
    props.store(out, "User properties of NAMS");//"props" is a property that contains some properties information.
    catch(Exception e){
    System.err.println("Error: " +e);
    Thanks for your attention!

    try{
    URL url = new URL("");
    URLConnection con = url.openConnection();
    con.setDoOutput(true);
    con.setDoInput(true);
    con.setUseCaches(false);
    con.setRequestProperty("Content-type", "text/plain");
    con.setRequestProperty("Content-length", data.length()+"");
    PrintStream out = new PrintStream(con.getOutputStream());
    out.print(data);
    out.flush();
    out.close();
    catch(Exception e){}

  • How read a file from applet?

    Hello.
    I have an applet which is in a signed jar file. And a configuration xml file. All I want to do is to put it near the jar file and access to it from applet. But applet cannot find it. I just want to read it simply. Also I don�t want to put it in a specified location on the server and want to have it near the jar file.
    Thanks very much.

    Check the API doc for Applet (that's java.applet.Applet). You call myApplet.getDocumentBase() to get the base URL (directory). I believe the base URL returned is actually the base URL of the HTML doc which your applet is embedded in. Add your xml filename to the end of the path. Then look at the API doc for java.net.URLConnection. You can call myURLConnection.getInputStream() to get an input stream of your xml.
    Nick

Maybe you are looking for

  • Text boxes not appearing - CAPTIVATE1.1

    I have a number of delegates using Cap1.1 - on some machines when recording screens, the automatic text boxes are not appearing when the recording has finished. (the "text box" option is checked on all PCs in the custom options settings) I`m sure i`v

  • How to track cartons in Warehouse

    Hi All       1. Our client is placing material in cartons and after palletilization it is placed in a avialable storage bin, for each pallet there will be 10 or 12 cartons will be placed , their requirement is that they have to track the carton some

  • Outstanding balance but everything is updated.

    i have an outstanding balance of $16.31. Ive updated my credit card information to pay it even though im using the same card i always have. But it doesnt ask if i want to use the card to pay the current balance off. can anyone help me. am i doin some

  • French accents / keyboard

    I've figured out how to use a keyboard that will spell check and add (occasionally) the French accents. But I'd like to control the accents since it does not always detect the correct spelling. How can I find a keyboard that had these accents? In an

  • Showing subscribed/unsubscribed podcasts in list view

    With past iTunes in List view I could quickly see to the right of the Podcast name, to what I am subscribed. Equally important I could note a desirable podcast that is currently unsubscribed. I do not see an easy way to do this with the current iTune