Problem inCreating File from a file on Linux, With JSP Code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AtulTiwari
    New Member
    • May 2007
    • 23

    Problem inCreating File from a file on Linux, With JSP Code

    I m using this code to make a file on my Windows Platform, and it is working fine.

    But when i run this programme on linux then it is not creating any file...
    I have Replaced the path "c:\\atul.t xt" to "/home/File/atul.txt" and "d:\\outgain.tx t" with "/home/File/outgain.txt"

    i have also set the permission for both File and home folder "wrx" it means full permission to the user.

    So could any one make it clear why it is not working properly.

    <%@ page import="java.io .*" %>
    <html>
    <body>
    <%


    FileInputStream in = null;
    FileOutputStrea m outfile = null;
    try {
    in = new FileInputStream ("c:\\atul.txt" );
    outfile = new FileOutputStrea m("d:\\outagain .txt");
    int c;

    while ((c = in.read()) != -1) {
    outfile.write(c );
    }

    }
    finally {
    if (in != null) {
    in.close();
    }
    if (outfile != null) {
    outfile.close() ;
    }
    }
    %>
    Success in creating File!
    </body>
    </html>
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Your servlet container or web server is probably running as another user. Try
    to set the file permissions to rwxrwxrwx and try again.

    kind regards,

    Jos

    Comment

    • AtulTiwari
      New Member
      • May 2007
      • 23

      #3
      Originally posted by JosAH
      Your servlet container or web server is probably running as another user. Try
      to set the file permissions to rwxrwxrwx and try again.

      kind regards,

      Jos

      Hi,
      Thanks for reply, but i m running the Tomcat as Supper user Account.

      and i run the Tomcat as

      su - tomcat -c/usr/local/tomcat/startup.sh


      and as i have already set the permission to "/home" and "File " folder in which the File will be created.

      am i right or Wrong?

      Comment

      • dmjpro
        Top Contributor
        • Jan 2007
        • 2476

        #4
        Originally posted by AtulTiwari
        I m using this code to make a file on my Windows Platform, and it is working fine.

        But when i run this programme on linux then it is not creating any file...
        I have Replaced the path "c:\\atul.t xt" to "/home/File/atul.txt" and "d:\\outgain.tx t" with "/home/File/outgain.txt"

        i have also set the permission for both File and home folder "wrx" it means full permission to the user.

        So could any one make it clear why it is not working properly.

        <%@ page import="java.io .*" %>
        <html>
        <body>
        <%


        FileInputStream in = null;
        FileOutputStrea m outfile = null;
        try {
        in = new FileInputStream ("c:\\atul.txt" );
        outfile = new FileOutputStrea m("d:\\outagain .txt");
        int c;

        while ((c = in.read()) != -1) {
        outfile.write(c );
        }

        }
        finally {
        if (in != null) {
        in.close();
        }
        if (outfile != null) {
        outfile.close() ;
        }
        }
        %>
        Success in creating File!
        </body>
        </html>

        Could u tell me the print stack trace in details?
        Then i would be able to solve ur problem.

        Kind regards,
        Dmjpro.

        Comment

        • AtulTiwari
          New Member
          • May 2007
          • 23

          #5
          Originally posted by dmjpro
          Could u tell me the print stack trace in details?
          Then i would be able to solve ur problem.

          Kind regards,
          Dmjpro.

          No Stack Trace is there,
          Actually code is not having any problem, it is executing fit and fine but the "outFile.tx t" is missing,i.e this file is not created yet.

          one more thing is there, that when i executed .java file with same code then the "OutFile.tx t " is created with no problem. but jsp file is creating problem but not giving any Exception or problem at all.
          PLZ do needfull

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            Originally posted by AtulTiwari
            No Stack Trace is there,
            Actually code is not having any problem, it is executing fit and fine but the "outFile.tx t" is missing,i.e this file is not created yet.

            one more thing is there, that when i executed .java file with same code then the "OutFile.tx t " is created with no problem. but jsp file is creating problem but not giving any Exception or problem at all.
            PLZ do needfull
            Hmm ... I see.
            Do one thing .... Handle the exception urself in JSP page and try to print the exception message in the page then tell me the specific error message u get.
            Have a good day.

            Kind regards,
            Dmjpro.

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by AtulTiwari
              No Stack Trace is there,
              Actually code is not having any problem, it is executing fit and fine but the "outFile.tx t" is missing,i.e this file is not created yet.

              one more thing is there, that when i executed .java file with same code then the "OutFile.tx t " is created with no problem. but jsp file is creating problem but not giving any Exception or problem at all.
              PLZ do needfull
              Maybe Tomcat does a 'chroot' (changes the root position of the file system).
              Try to find the file:
              Code:
              find / -name OutFile.txt -print
              If you can find it anywhere in the file system my guess was right ;-)

              kind regards,

              Jos

              Comment

              Working...