Results 1 to 8 of 8
  1. #1
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    150
    Rep Power
    7

    Default [SOLVED] File is Not Moving

    i wants to move a file from one location to another location , Here is my code
    import java.io.*;
    import java.net.*;

    import javax.servlet.*;
    import javax.servlet.http.*;

    public class upload extends HttpServlet
    {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {


    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    String path=request.getParameter("Jazz");
    File f=new File(path);
    String s=f.getAbsolutePath();
    File file = new File(s);

    // Destination directory
    File dir = new File("D:\\moved");

    // Move file to new directory
    boolean success = file.renameTo(new File(dir, file.getName()));
    if (!success) {
    System.out.println("File is not moved");
    }



    }
    }
    Can you help me...

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    150
    Rep Power
    7

    Default

    yeah ..please check my code....

  4. #4
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default

    Try this.

    From this part of your code:
    Java Code:
    // Destination directory
    File dir = new File("D:\\moved");
    
    // Move file to new directory
    boolean success = file.renameTo(new File(dir, file.getName()));
    if (!success) {
    System.out.println("File is not moved");
    TO this:
    Java Code:
    // Destination directory
    File dir = new File("D:\\moved\\" + file.getName());
    
    // Move file to new directory
    boolean success = file.renameTo(dir);
    if (!success) {
    System.out.println("File is not moved");
    ^_^ i hope that helps
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    You know, that is a long way away from a file upload. If by "move" a file, you mean upload it from the client, and "move" it to the server, you are no where's close to where you want to be. And if that is not what you mean then "upload" is very bad name for your class (which it does not stick to the standard naming conventions anyway, but that's another complaint).

    I can't vouch for the quality of this site, but if file uplaod is what you really want, try this Java Servlet / JSP File Upload: Parse HTML / XHTML Form Data. Set Maximum File Size

  6. #6
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    150
    Rep Power
    7

    Unhappy

    i tried with the folowing code and get succeeded with stnd alone..where as if i implement in web appliction i can't....let me try the given link and ll let my status..

    thanks for replying me.....

    jazz
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package com.demo;

    import java.io.File;

    public class Copy {
    public static void main(String[] args) {
    File file = new File("D:\\tiff\\Invo.txt");

    // Destination directory
    File dir = new File("D:\\moved");

    // Move file to new directory
    boolean success = file.renameTo(new File(dir, file.getName()));
    if (!success) {
    System.out.println("File is not moved");
    }
    }
    }

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Like I said, what are you trying to do? Are you trying to "move" a file from the client to the server? If so, this doesn't even come close to what you want. Read that tutorial.

    If it is that you want to move a file from one directory on the client to another directory on the client , you can't do that either.

    If you want to "move" a file from the server to the client, that is called a download and still cannot be accomplished by this code, in that case, simply give a link to it, and let the client decide where, and how, to save it.

    If you want to move a file from one directory on the server to another directory on the server, then this will work, as long as the user under which the web container process is running has access to those directories.

  8. #8
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    150
    Rep Power
    7

    Default

    I am developing a web application which includes upload a file using browse option from client and upload it into server location..

    i read ur link and let you know.

    Thnks
    Jazz

Similar Threads

  1. moving slider with key event
    By adam405 in forum New To Java
    Replies: 1
    Last Post: 03-18-2008, 03:50 PM
  2. moving image - PROBLEM
    By Triss in forum New To Java
    Replies: 3
    Last Post: 01-17-2008, 06:52 PM
  3. Moving icons on your desktop
    By Leprechaun in forum New To Java
    Replies: 3
    Last Post: 12-14-2007, 10:07 AM
  4. moving a file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-10-2007, 07:52 PM
  5. examples of moving objects
    By fred in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •