Help on using servlets to write files to web server

Hi,
I am chetan from India, I have developed the WebSite www.bhavishya.net. I am encountering a serious problem in writing into a text file. I am unable to configure the path of the text file. While on Linux i got it (path - "/home/bhavishya/ErrorLog.txt"). But now i am using Windows Environment. The code is as follows.
public String ewrite(String str)
String err = "File updated";
try
Date d = new Date();
BufferedWriter bwout = null;
// for Web Server
try
//BufferedWriter out = new BufferedWriter(new FileWriter("/home/bhavishya/ErrorLog.txt", true)); // For Linux
bwout = new BufferedWriter(new FileWriter("./bhavishya/logs/ErrorLog.txt", true));
bwout.write(d.toLocaleString()+" : "+str+"\n");
catch (RuntimeException e1) {err = e1.toString(); e1.printStackTrace();}
System.out.println("ErrorLog - 21");
bwout.close();
catch (IOException e) { System.out.println(e); }
return err;
The file is neither created or written into even if i am creating it.
Regards,

Does the path to the file exist? Otherwise you should try adding a File.mkdirs() call in there to create the directory where you want to write the logfile to. Otherwise writing the file will fail.

Similar Messages

  • Applet can't read local file on web server, security issue!

    There is any way to read/write files of web server through the applet except the Signed Applet.
    If any idea the reply me soon.
    Thanks in advance

    Applets are downloaded from web servers and execute on the client machine.
    Therefore they have no access to the web server file system, signed or not.
    They could have access to the client file system (the machine where they run),
    but for security reasons only signed applets have this privilege.
    So to answer your question, you sign if you want to access client files.
    To access web server files, you don't need to sign the applet, but you need
    to provide some method of accessing files remotely, for instance:
    - Files published for the web can be read using HTTP
    - Files can be read or writen with the help of an FTP server on the same machine as the web server
    - A servlet running on the HTTP server can collaborate with your applet to exchange files

  • How To read/write file on remote server in java

    Hi All,
    How To read/write file on remote server in java? I mean using URL - http://www.xyz.com can I right file to that perticular server.
    Thanks in advance

    If your server support a means of uploading files you can.
    A popular means is [http://en.wikipedia.org/wiki/WebDAV]
    However, by default web server don't allow you upload files, its usually something you need to configure or install.
    I suggest you have a look at your web servers documentation.

  • AdobeAcrobat/Reader that is running can not be used to view PDF Files in Web Browser...what do I need to do to fix this..

    I just got Windows 7 and have been having problems since loading it. Most of my drivers only go to Vista and don't recognize 7.
    I have trying to download some manuals from their website
    and keep getting this message; Adobe Acrobat/reader that is running can not be used to view PDF files in Web Browser.

    Could I suggest a workaround for PDFs until a solution is posted? Open them directly in the Adobe application rather than in a browser tab.
    In your Adobe application(s), go to:
    Edit > Preferences > Internet
    Then uncheck "Display PDF in browser"
    (There are very few sites where having PDF integrated is really beneficial.)

  • How to delete a file on web server without using FTP

    Hi All
    I hv given a facility to a site user to upload some files..
    And an interface to web administrator to view all the files..
    I want to know how can i write a code in JSP which allow the web administrator to delete any of that file which is not of his/her interest through provided interface only.
    OR
    Is it possible to delete a particular file from web server without getting login into FTP account
    Thanx

    new File(strFileName).remove;
    Simply as this.
    Don't forget to import java.io.FileInputStream.

  • Help Setting Up File and Web Server in OS 8.6

    I have an OS 8.6 400mhz G3 B&W with 512mb RAM and an 80GB HD. It has the OEM operating system which is 8 on it. First I can't access the computer via afp from a Leopard Machine (Yes appletalk is enabled.). It gives me the error -36. Which is "The Finder can not complete the operation because some data in _____________ could not be read or written. I need this computer for a File and Web server. How could I make it accessible via AFP and FTP? I thought about linux but it requires a terminal like interface and I don't like that.

    To begin with, have a look at the IV. Troubleshooting section of KB article 106461:
    "Mac OS X 10.4 and later don't support Personal File Sharing (or other AFP) over Appletalk, though by initiating the connection from the opposite direction you could still achieve an IP connection from a Mac OS 8 computer to a sharing Mac OS X computer."
    Regarding servers: There is a built-in web server in Mac OS 8.6 (see the help system for details). Alternatively, the (now) free NetPresenz could perhaps be of interest.
    Jan

  • Error: java.lang.OutOfMemoryError when uploading CSV files to web server

    Hi experts,
    I have made a JSP page from which clients load csv files to web server. I am using Tomca 4.1 as my web server and JDK 1.3.1_09.
    The system works fine when uploadiing small csv files, but it crashes when uploading large CSV files.
    It gives me the following error:
    java.lang.OutOfMemoryError
         <<no stack trace available>>
    This is the code that I used to load files....
    <%
    String saveFile = "";
    String contentType = request.getContentType();
    if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0))
         DataInputStream in = new DataInputStream(request.getInputStream());
         int formDataLength = request.getContentLength();
         byte dataBytes[] = new byte[formDataLength];
         int byteRead = 0;
         int totalBytesRead = 0;
         while (totalBytesRead < formDataLength)
              byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
              totalBytesRead += byteRead;
         String file = new String(dataBytes);
         saveFile = file.substring(file.indexOf("filename=\"") + 10);
         saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
         saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
         int lastIndex = contentType.lastIndexOf("=");
         String boundary = contentType.substring(lastIndex + 1,contentType.length());
         int pos;
         pos = file.indexOf("filename=\"");
         pos = file.indexOf("\n", pos) + 1;
         pos = file.indexOf("\n", pos) + 1;
         pos = file.indexOf("\n", pos) + 1;
         int boundaryLocation = file.indexOf(boundary, pos) - 4;
         int startPos = ((file.substring(0, pos)).getBytes()).length;
         int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
         String folder = "f:/Program Files/Apache Group/Tomcat 4.1/webapps/broadcast/file/";
         //String folder = "10.28.12.58/bulksms/";
         FileOutputStream fileOut = new FileOutputStream(folder + saveFile);
         //out.print("Saved here: " + saveFile);
         //fileOut.write(dataBytes);
         fileOut.write(dataBytes, startPos, (endPos - startPos));
         fileOut.flush();
         fileOut.close();
         out.println("File loaded successfully");
    //f:/Program Files/Apache Group/Tomcat 4.1/webapps/sms/file/
    %>
    Please can anyone help me solve this problem for me...
    Thanx...
    Deepak

    I know it may be hard to throw away all this code, but consider using the jakarta fileupload component.
    I think it would simplify your code down to
    // Create a factory for disk-based file items
    FileItemFactory factory = new DiskFileItemFactory();
    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload(factory);
    // Parse the request
    List /* FileItem */ items = upload.parseRequest(request);
    // Process the uploaded items
    Iterator iter = items.iterator();
    while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();
        if (item.isFormField()) {
            processFormField(item);
        } else {
            // item is a file.  write it
            File saveFolder = application.getRealPath("/file");          
            File uploadedFile = new File(saveFolder, item.getName());
            item.write(uploadedFile);
    }Most of this code was hijacked from http://jakarta.apache.org/commons/fileupload/using.html
    Check it out. It will solve your memory problem by writing the file to disk temporarily if necessary.
    Cheers,
    evnafets

  • Deploying servlets in the Sun One Web Server 6.1

    Friends, Please let me know how to deploy servlets in the Sun One Web Server 6.1.
    Thanks in advance,
    Madan.

    You cannot get that behavior.
    When an SSL client and server negotiate the connection, the client sends a list of all the cipher suites it supports. From that list the server will pick the most secure cipher suite which it also supports (if the server doesn't support any of the cipher suites proposed by the client, the connection establishment will fail).
    RC4 (128bit) is more secure than 3DES (112 bit). Thus, a server will never pick 3DES above RC4_128 if both are valid options (i.e. when both client and server support both). If you really wanted to force use of 3DES you need to disable RC4_128 in the server (or all the clients; or both).

  • Use servlet read .csv file by ie, but why two more " ?

    Hi , friends
    following is the key method in my servlet used to read .csv file to ie , but , after I read file to client side , I found that in the both sides of every line " was added, so the csv file can have only one column (many columns was merged into one column), that was not what i want, who guys can find some idea? thanks for your enthusiasm!
    void serveRemoteFile(String sFileName, String sContentType, HttpServletRequest req, HttpServletResponse res, StringBuffer sbLog, Runtime rt){
    FileInputStream in = null;
    ServletOutputStream out = null;
    byte bBuf[] = null;
    int nLen;
    if (isBlank(sContentType) || isBlank(sFileName))
    return;
    res.setStatus(res.SC_OK);
    res.setContentType(sContentType);
    res.setHeader("Content-Disposition", "inline;filename= temp.csv");
    try {
    in = new FileInputStream(sFileName);
    out = res.getOutputStream();
    bBuf = new byte[1024];
    while ( (nLen = in.read(bBuf,0,1024)) != -1) {
    out.write(bBuf, 0, nLen);
    out.flush();
    out.close();
    }catch (FileNotFoundException e){
    errorPage(req,res,sbLog);
    }catch (IOException e){
    errorPage(req,res,sbLog);

    Excel uses a weird CSV file format. You can find more information about it and a Java library to read data from it here:
    http://ostermiller.org/utils/ExcelCSV.html

  • Applet write file on coming server without servlet

    Hi, I have an applet that needs to write a new file on the server that's LOADED FROM. Here are my questions:
    1) can the applet write this file WITHOUT using a servlet on the server side?
    2) if it's possible, could someone send me an example to explain how to do it?
    Thanks in advance, have a nice day

    1) can the applet write this file WITHOUT using a
    servlet on the server side?No,it can't. Well, on the server is not necessary to
    have a java servlet but you should have "something"
    that can receive your data, understand it and save it.
    A small PHP script is enough.
    Hope this help

  • How to Download a file from web server using servlets

    how do we download a file from Java Web Server connecting to oracle database
    it should start as soon a i click a button in my html browser
    please reply as it is needed to complete my project to submited to the collage

    With SQLJ you can do it.
    When you look at:
    http://otn.oracle.com/sample_code/tech/java/sqlj_jdbc/files/basic/basic.htm
    or
    http://otn.oracle.com/sample_code/tech/java/sqlj_jdbc/files/advanced/advanced.htm
    There are samples for reading LONGRAW / BLOB from Database. If you want use it in servlet you have to pass the result to the responce object, set the correct mime-type and set the response.setContentLength( xx). This is for some PlugIns nessessary (pdf).
    regards Dietmar

  • OPEN DATA SET to write files in application server folder - some of the files are missing

    Hi,
    I'm using OPEN DATASET statement in batch job to write the files in application server. what i'm experiencing is when i schedule the batch job all the files are not writing into the folder.
    If i run the report again to write the missed files, the files are writing into the application server folder.
    after opening the dataset, i'm closing it. do we need to give any delay between creation of the files? or until the first write operation is done, 2nd one can't start ..how can we achieve this.
    Thanks for your help in advance.
    Thanks,
    Adi.

    Hello Bathineni,
    Are you using the sy-subrc check after the OPEN DATASET statement.
    If not use a sy-subrc check and transfer the contents to file only when the OPEN DATASET returns value sy-subrc = 0.
    if sy-subrc is 8 repeat the same loop say for 3 attempts until the OPEN DATASET becomes 0.
    DO 3 TIMES. <---- put any number of attempts as you need
    OPEN DATASET.
    IF sy-subrc = 0.
       TRANSFER contents to file.
       EXIT.
    ENDIF.
    ENDDO.
    CLOSE DATASET.
    Regards,
    Thanga

  • Read/write file located on server

    Hi,
    I want to read a TXT file located on server and depending on the response I want to write an XML file also located on server
    how could be it possible in JAVA
    please help me
    alpesh

    the TXT file is located on the WEB server, and I want
    to read the TXT file's content From the client, I assume. URLConnection. Or your favorite browser.
    the content is the User InformationAnd you want to write that on the server. Forget it, unless you have CGI or FTP or a servlet or whetever to process incoming requests or allows you to connect to the fie system somehow (WebDAV).

  • Write to file??? looking for a solution to write file to the server

    Dear all,
    Since most browsers forbid all file access, so is there is another way to write file to server in applet??? or is there an alternative using combination of JSP??
    Thank you for your attention,
    Dan

    If you have access to the server you are writing the file to then you could have your applet collect information and send it to the server in a form. Then write a bean or other class that handles it and writes it to the server.

  • Write files on a Server with an Applet

    How can I write files (like php) on my server with an applet? Can anybody explain it step for step?

    Yes... but then...? I thinked applets have no
    permission to write files...The correct sentence is: unsigned applets don't have permission to write files locally. Also, unsigned applets cannot access any other server than the one they came from. You don't seem to do either, so it might work without signing. And if you need sining, just sign it.
    What I don't know is how you can use an FTP or any other 3rd party library in combination with an applet... dunno if the user needs to have it locally or whether the applet can pull it off your server if needed.

Maybe you are looking for

  • HT201269 how come all of a sudden my computer will no longer recognize my iPhone?

    my phone was working fine, and one day i pluged it into my computer USB as i always do, to check updates, sync, and load pictures on my computer. well a  couple weeks ago, i did this as i did every day prior, and bang it doesnt work. went out and got

  • Wan run third party  with PR-- PO-- GRN-IV- PAY and Consumptio later

    Dear All, I have an business requirement where I need to create a third party sale scenario where as the material which I am selling is procure from vendor . Scenario is Step 1  Sales order with third party scenario where PR is auto generate with sal

  • SRM 7 ECS : Contract Item in Invoice witout PO reference

    Hello Gurus, We are implementing SRM 7 with ECS. We create Invoice from scratch without PO reference. In "Add item" we have a very much interesting option called "Contract item". Unfortunately this remains desperately gray at the moment. We only have

  • Inactive Condition Types

    Dear Sapients,             I need ur valuable solution in solving an issue. I have created a pricing procedure for domestic sales and in tht some condition types r in inactive mode. I have verified the settings in condition types n also checked the c

  • Totally in a mess

    Just what has iPhoto done to all my photos??? They are in a complete mess. Inside my photos folder there are several folder dated by year - this is fine. Yet inside these folders are folders upon folders upon folder all numbered, some with nothing in