Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-07-2008, 07:57 AM
jazz2k8's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 101
jazz2k8 is on a distinguished road
[SOLVED] File is Not Moving
i wants to move a file from one location to another location , Here is my code
Quote:
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...
__________________
visit :
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-07-2008, 08:04 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
I didn't check your code. Did you try with renameTo() option?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-07-2008, 08:23 AM
jazz2k8's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 101
jazz2k8 is on a distinguished road
yeah ..please check my code....
__________________
visit :
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-07-2008, 08:34 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 191
Eku is on a distinguished road
Try this.

From this part of your code:
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:
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-07-2008, 08:50 AM
Senior Member
 
Join Date: Jun 2008
Posts: 181
masijade is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-07-2008, 09:52 AM
jazz2k8's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 101
jazz2k8 is on a distinguished road
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
Quote:
/*
* 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");
}
}
}
__________________
visit :
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 07-07-2008, 10:00 AM
Senior Member
 
Join Date: Jun 2008
Posts: 181
masijade is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 07-07-2008, 11:58 AM
jazz2k8's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 101
jazz2k8 is on a distinguished road
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
__________________
visit :
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
moving slider with key event adam405 New To Java 1 03-18-2008 04:50 PM
moving image - PROBLEM Triss New To Java 3 01-17-2008 07:52 PM
Moving icons on your desktop Leprechaun New To Java 3 12-14-2007 11:07 AM
moving a file Java Tip Java Tips 0 11-10-2007 08:52 PM
examples of moving objects fred New To Java 1 08-07-2007 07:06 PM


All times are GMT +3. The time now is 04:01 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org