Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-23-2009, 09:45 AM
raghu9198's Avatar
Member
 
Join Date: Dec 2008
Posts: 32
Rep Power: 0
raghu9198 is on a distinguished road
Question to change the destination folder
Hi all,
Greeting of the day
I have written code to upload a file and save it using a jsp. It is being saved in default folder.Now I want to change my destination
folder how can do that ?

here is my code


<%@ page import="java.io.*" %>
<%
//to get the content type information from JSP Request Header
String contentType = request.getContentType();
//here we are checking the content type is not equal to Null and
//as well as the passed data from mulitpart/form-data is greater than or
//equal to 0
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0))
{
DataInputStream in = new DataInputStream(request.getInputStream());
//we are taking the length of Content type data
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
//this loop converting the uploaded file into byte code
while (totalBytesRead < formDataLength)
{
byteRead = in.read(dataBytes, totalBytesRead,formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
//for saving the file name
String saveFile = file.substring(file.indexOf("C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\test="") + 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;
//extracting the index of file
pos = file.indexOf("C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\test="");
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;
// creating a new file with the same name and writing the content in new file
FileOutputStream fileOut = new FileOutputStream(saveFile);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
%>
<Br><table border="2"><tr><td><b>You have successfully uploaded the file by the name of:</b>
<% out.println(saveFile); %></td></tr></table> <%
}
%>

I want to change the destination folder which is located in the other drive
Please help


Thanks in advance
Raghu
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

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

BB 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
How to create Folder View jazz2k8 Advanced Java 2 10-24-2008 03:04 PM
want to run my code from any folder ? Shyam Singh New To Java 1 08-12-2008 02:31 PM
how to display chat window in both source and destination machine bu.pradeep Networking 1 08-08-2008 04:20 AM
folder cloning jad Advanced Java 1 07-01-2008 01:28 AM
add password to folder ismailsaleh AWT / Swing 1 01-08-2008 06:46 AM


All times are GMT +2. The time now is 01:30 AM.



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