|
|
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.
|
|

07-07-2008, 07:57 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 101
|
|
|
[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...
__________________
visit : To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

07-07-2008, 08:04 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
|
|
|
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.
|
|

07-07-2008, 08:23 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 101
|
|
|
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.
|
|

07-07-2008, 08:34 AM
|
|
Senior Member
|
|
Join Date: May 2008
Location: Makati, Philippines
Posts: 191
|
|
Try this.
From this part of your 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:
// 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.
|
|

07-07-2008, 08:50 AM
|
|
Senior Member
|
|
Join Date: Jun 2008
Posts: 181
|
|
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
|
|

07-07-2008, 09:52 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 101
|
|
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");
}
}
}
__________________
visit : To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

07-07-2008, 10:00 AM
|
|
Senior Member
|
|
Join Date: Jun 2008
Posts: 181
|
|
|
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.
|
|

07-07-2008, 11:58 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 101
|
|
|
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.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|