How to upload and Download the file in a system through java programing

I am trying to upload a file as well as want to download the uploaded file in my system....I don't have any server an all.
I want to implement this in my system only .
I got this code but i don't know ,where i have to make the change and what are the parameters i have to pass.
can any one help me on this code ....please
here some piece of code
File Upload and Download Code Example
package com.resource.util;
public class FileUpload
public void upload( String ftpServer, String user, String password,
String fileName, File source ) throws MalformedURLException,
IOException
if (ftpServer != null && fileName != null && source != null)
StringBuffer sb = new StringBuffer( "ftp://" );
// check for authentication else assume its anonymous access.
if (user != null && password != null)
sb.append( user );
sb.append( ':' );
sb.append( password );
sb.append( '@' );
sb.append( ftpServer );
sb.append( '/' );
sb.append( fileName );
* type ==> a=ASCII mode, i=image (binary) mode, d= file directory
* listing
sb.append( ";type=i" );
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try
URL url = new URL( sb.toString() );
URLConnection urlc = url.openConnection();
bos = new BufferedOutputStream( urlc.getOutputStream() );
bis = new BufferedInputStream( new FileInputStream( source ) );
int i;
// read byte by byte until end of stream
while ((i = bis.read()) != -1)
bos.write( i );
finally
if (bis != null)
try
bis.close();
catch (IOException ioe)
ioe.printStackTrace();
if (bos != null)
try
bos.close();
catch (IOException ioe)
ioe.printStackTrace();
else
System.out.println( "Input not available." );
}

At least that is what the code you posted suggests to me.It looks like that to me too.
I believe that
URLConnection urlc = url.openConnection(url);Will return you an FTP URLConnection implementation if you pass it a ftp:// url
So for simple FTP ops, you don't need any external libs.
Actually, looking at your code, this is already what you are doing, so I really don't get this:
am not using FTP server..... i want to implement in my system only ....So How i will do.
Can you give me any idea based on this code Can you explain a bit more what you need?
patumaire

Similar Messages

  • How to upload and download any file from plsql through weblogic server

    hi all,
    how to upload and download any file from plsql through weblogic server? i am using oracle 10g express edition and jboss.
    Thanks and Regards,
    MSORA

    hi bala ,
    for a windown server u can use VNC (virtual network connection) which opens a session on u r desktop later u can drag and drop form there vice versa and for a linux box you can use Win SCP which helps to open a session with interface to u r desktop in both cases you can upload and down load files very easiy just as we drag and drop items in a simple pc .. we use the same technique...
    bye
    vamshi

  • Upload and download the file same name but different extension from the document library.

    HI,
         I am using the Client Object Model (Copy. Asmx ) To upload and download the file from the document library.
    I am having the mandatory File ID for the each Document.
    I tried to upload the the document (KIF53.txt) with File ID (KIF53) uploaded successfully.
    Again I tried to Upload the document(KIF53.docx) With File ID(KIF53) its uploaded the file but it not upload the File ID in the Column
    Please find the below screen shoot for the reference.

    thanks ashish
    tried 
    My requirement is to create the  folder and sub folder in SharePoint document library. If already exist leave it or create the new folder and the subfolder in the Document library using client side object model
    I able to check for the parent folder.
    But cant able to check the subfolder in the document library.
    How to check for  the sub folder in the document library?
    Here is the code for the folder IsFolder alredy Exist.
    private string IsFolderExist(string InputFolderName)
            string retStatus
    = false.ToString();
            try
                ClientContext context
    = newClientContext(Convert.ToString(ConfigurationManager.AppSettings["DocumentLibraryLink"]));
    context.Credentials = CredentialCache.DefaultCredentials;
                List list
    = context.Web.Lists.GetByTitle(Convert.ToString(ConfigurationManager.AppSettings["DocumentLibraryName"]));
                FieldCollection fields
    = list.Fields;
                CamlQuery camlQueryForItem
    = new CamlQuery();
    camlQueryForItem.ViewXml = string.Format(@"<View 
    Scope='RecursiveAll'>
    <Query>
                          <Where>
    <Eq>
    <FieldRef Name='FileDirRef'/>
    <Value Type='Text'>{0}</Value>
                            </Eq>
    </Where>
    </Query>
    </View>", @"/sites/test/hcl/"
    + InputFolderName);
    Microsoft.SharePoint.Client.ListItemCollection listItems
    = list.GetItems(camlQueryForItem);
    context.Load(listItems);
    context.ExecuteQuery();
                if (listItems.Count
    > 0)
    retStatus = true.ToString();
                else
    retStatus = false.ToString();
            catch (Exception ex)
    retStatus = "X02";
            return retStatus;
    thanks
    Sundhar 

  • How to upload  and download a files into AL11 directory in ABAP

    Hi,
                   How to upload  and download a files into AL11 directory in ABAP
    thanks
    Moderator message: please search for available information/documentation.
    Edited by: Thomas Zloch on Mar 21, 2011 9:18 AM

    You should try one of these forums for an answer to your question:
    http://swforum.sun.com/jive/forum.jspa?forumID=116
    http://community.java.net/netbeans
    http://linux.java.net

  • How to store xml data into file in xml format through java program?

    HI Friends,
    Please let me know
    How to store xml data into file in xml format through java program?
    thanks......
    can discuss further at messenger.....
    Avanish Kumar Singh
    Software Engineer,
    Samsung India Development Center,
    Bangalore--560001.
    [email protected]

    Hi i need to write the data from an XML file to a Microsoft SQL SErver database!
    i got a piece of code from the net which allows me to parse th file:
    import java.io.IOException;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    import org.apache.xerces.parsers.SAXParser;
    import java.lang.*;
    public class MySaxParser extends DefaultHandler
    private static int INDENT = 4;
    private static String attList = "";
    public static void main(String[] argv)
    if (argv.length != 1)
    System.out.println("Usage: java MySaxParser [URI]");
    System.exit(0);
    String uri = argv[0];
    try
    XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
    MySaxParser MySaxParserInstance = new MySaxParser();
    parser.setContentHandler(MySaxParserInstance);
    parser.parse(uri);
    catch(IOException ioe)
    ioe.printStackTrace();
    catch(SAXException saxe)
    saxe.printStackTrace();
    private int idx = 0;
    public void characters(char[] ch, int start, int length)
    throws SAXException
    String s = new String(ch, start, length);
    if (ch[0] == '\n')
    return;
    System.out.println(getIndent() + " Value: " + s);
    public void endDocument() throws SAXException
    idx -= INDENT;
    public void endElement(String uri, String localName, String qName) throws SAXException
    if (!attList.equals(""))
    System.out.println(getIndent() + " Attributes: " + attList);
    attList = "";
    System.out.println(getIndent() + "end document");
    idx -= INDENT;
    public void startDocument() throws SAXException
    idx += INDENT;
    public void startElement(String uri,
    String localName,
    String qName,
    Attributes attributes) throws SAXException
    idx += INDENT;
    System.out.println('\n' + getIndent() + "start element: " + localName);
    if (localName.compareTo("Machine") == 0)
    System.out.println("YES");
    if (attributes.getLength() > 0)
    idx += INDENT;
    for (int i = 0; i < attributes.getLength(); i++)
    attList = attList + attributes.getLocalName(i) + " = " + attributes.getValue(i);
    if (i < (attributes.getLength() - 1))
    attList = attList + ", ";
    idx-= INDENT;
    private String getIndent()
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < idx; i++)
    sb.append(" ");
    return sb.toString();
    }// END PRGM
    Now , am not a very good Java DEv. and i need to find a soln. to this prob within 1 week.
    The next step is to write the data to the DB.
    Am sending an example of my file:
    <Start>
    <Machine>
    <Hostname> IPCServer </Hostname>
    <HostID> 80c04499 </HostID>
    <MachineType> sun4u [ID 466748 kern.info] Sun Ultra 5/10 UPA/PCI (UltraSPARC-IIi 360MHz) </MachineType>
    <CPU> UltraSPARC-IIi at 360 MHz </CPU>
    <Memory> RAM : 512 MB </Memory>
    <HostAdapter>
    <HA> kern.info] </HA>
    </HostAdapter>
    <Harddisks>
    <HD>
    <HD1> c0t0d0 ctrl kern.info] target 0 lun 0 </HD1>
    <HD2> ST38420A 8.2 GB </HD2>
    </HD>
    </Harddisks>
    <GraphicCard> m64B : PCI PGX 8-bit +Accel. </GraphicCard>
    <NetworkType> hme0 : Fast-Ethernet </NetworkType>
    <EthernetAddress> 09:00:30:C1:34:90 </EthernetAddress>
    <IPAddress> 149.51.23.140 </IPAddress>
    </Machine>
    </Start>
    Note that i can have more than 1 machines (meaning that i have to loop thru the file to be able to write to the DB)
    Cal u tellme what to do!
    Even better- do u have a piece of code that will help me understand and implement the database writing portion?
    I badly need help here.
    THANX

  • How to upload and download a file in server side program

    Give me a sample code for the file upload and download using Server side program.

    You should try one of these forums for an answer to your question:
    http://swforum.sun.com/jive/forum.jspa?forumID=116
    http://community.java.net/netbeans
    http://linux.java.net

  • How to upload and save a file sent by client through a form

    Hi to everyone!! I wanted to know how to save in a servlet a file submited to me through a form. (in a form I have an <INPUT TYPE="FILE"> field). I know that the file was uploaded because I used a mini sever that shows me that. But I don't know how to save it for a late using. For those who answer me, please write down the code, or give me a link for such a code.

    For the html form, u need:
    <FORM METHOD="POST" ACTION="servletOrJsp" ENCTYPE="multipart/form-data">
    <INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><BR>
    <INPUT TYPE="SUBMIT" VALUE="Upload">
    </FORM>
    In the servlet/jsp, you need to handle multipart request which you can't get it by just request.getParameter("FILE1").
    Try jspSmartUpload, is a free and easy to use API specifically designed in this situation. The examples given are pretty straight forward :)
    http://www.jspsmart.com

  • How to upload and download files using FTP to a server(webserver) in JSP

    I have to upload and download multiple files Of(size >5 MB)using FTP to a
    Server(webserver) in JSP
    how to do that ?

    Or he could create his own tag libraries, no? :)One supposes that, technically, one could create a taglib wrapper around an existing FTP library. There might be licensing issues with distributing that taglib wrapper.
    Of course, one could find the FTP RFC online, read it, and implement one's own FTP client implementation, complete with a tag library access point.

  • How do I upload and attach the file to Service Request

    [This thread was migrated from the On Demand Developer Forum in the old Siebel Community]
    drangineni
    New Contributor
    Hi,
    I am trying to upload a file and add it to a Service object as an
    attachement. I greatly appreciate if you could provide any code or
    sample...
    Thanks.
    Daya
    Product: CRM OnDemand
    10-21-2006 10:58 AM
    Re: How do I upload and attach the file to Service Request...
    BigSlick
    Valued Contributor
    On Demand doesn't support adding attachments via web services. One
    solution I've seen is depending on the scenario is to create a web link
    field on an object that's based on a custom text field. Your web service
    can populate that custom field and the web link can generate a dynamic
    link to the file in On Demand's UI. However, this depends on where the
    attachment is located and if the user needs some sort of firewall access.
    Hope this helps
    -BigSlick
    10-23-2006 11:43 AM
    ==============================================================================
    Click on the board or message subject at the top to return.

    Yes this still holds ture.
    Bardo

  • Upload and Download of files

    I am working on a web site development work. I am working with STRUTS framework tht is made over the jsp tag library..Can any one help me about how to upload and download files from server and to the server.If possible using struts framework. Pls do give a pratical example..
    regards jay

    Like this:
            //upload
            String fileName = formFile.getFileName();
         Sting  destFile = "c:/upload/" + fileName;//path to save the upload file on server
         try {
                 InputStream     in = formFile.getInputStream();
              OutputStream     out = new FileOutputStream( new File(destFile) );
              int n = 0;
              byte[] buff = new byte[8192];
              while( (n = in.read( buff, 0, 8192 )) != -1 ) {
                   out.write( buff, 0, n );
              out.close();
              in.close();     
            }catch(Exception e){
            //download
            String serverFile = "c:/upload/a.txt";//file path on server to be downloaded
            File serverF = new File(serverFile);
            response.setContentType("text/html");
         response.setHeader("Content-Disposition","attachment;filename="+serverF.getFileName()+";");
         try {
             ServletOutputStream outStream = response.getOutputStream();
             FileInputStream stream = new FileInputStream(serverF);
             BufferedInputStream  bis = new BufferedInputStream(stream);
             BufferedOutputStream bos = new BufferedOutputStream(outStream);
             byte[] buff = new byte[2048];
             int bytesRead;
                try{
                 while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                      bos.write(buff, 0, bytesRead);
             } catch (Exception e) {
                } finally {
            if (bis != null) bis.close();
            if (bos != null) bos.close();
            if (stream != null) stream.close();
         }catch (IOException e){
         }

  • How to upload and download image?

    hi,
    can anyone send me links  how to to upload and download image to and from sever
    Here i am using amfphp,mysql,php
    i have an button and textfield.when i clicked on the button the path will be stored into database and image will be
    stored into server folder.Similarly for edit i want to display that image to end user.How to do that?

    hi,
    you need to first bring the image into your sap system.
    that you can achieve by right clicking you application and then clicking on create mime object.
    check out this link too:
    Re: how to upload an image file(or any file) in mime using file upload ui eleme
    then you have to insert an image ui element in your view.
    check out the link:
    http://help.sap.com/saphelp_nw04/helpdata/en/f3/1a61a9dc7f2e4199458e964e76b4ba/content.htm
    according to you req i think you need to upload and download the image file in your system using a button. so for this you can follow the below link:
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/00062266-3aa9-2910-d485-f1088c3a4d71
    hope this will surely help you!!!
    thanks & regards,
    punit raval.
    Edited by: punit raval on Jun 24, 2009 9:56 AM

  • Apex application file -upload and download a file.

    hi
    im having an issue with an application i created,its about uploading and downloading a file in application.the application is working and was able to upload and download a file but i have not idea there the file is stored in the application database,try to search for the file,its something dealing with the apex_application_file and i cant find it.
    Any idea where the file is stored?
    thnx
    nivesh

    Dear nivesh!
    If you upload a file into an APEX application the file is temporarily stored in the APEX_APPLICATION_FILES table. If you close your current application page the APEX_APPLICATION_FILES table will be cleared. You should create your own table to store files in a BLOB column. I've create an example for uploading images into an APEX application on apex.oracle.com. If you want to have a look at it please use the following credentials:
    Workspace: flo_demo
    Username: dev_null
    Password: password
    Application: 61811
    Yours sincerely
    Florian W.

  • Bapi to upload and download the leave details

    Hi all,
          Can  u please tell me a bapi to upload and download the leave details for the infotype 2001.
    Thanks.

    Hi
    Warning! The API methods "Delete," "Approve," "Create," and "Request," and "Change," as well as their corresponding RFCs:
    <b>bapi_absence_delete
    bapi_absence_create
    bapi_absence_approve
    bapi_absence_request
    bapi_absence_change</b>
    are <b>no longer valid</b>. Using these APIs can create inconsistencies in time data.
    Instead, use the corresponding API Methods "ManageDelete," "ManageCreation," and "ManageChange" for the Business Object BUS7007, as well as the following corresponding RFCs:
    <b>bapi_ptmgrattabs_mngdelete
    bapi_ptmgrattabs_mngcreation
    bapi_ptmgrattabs_mngchange</b>
    Regards
    Raj

  • HT4009 I did not download the in-app purchase at time of original App download, now I cannot figure out how to find and download the in-app purchase.  Please help!

    did not download the in-app purchase at time of original App download, now I cannot figure out how to find and download the in-app purchase.  Please help!

    Hello paddyliverpool,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    How to report an issue with your iTunes Store, App Store, Mac App Store, or iBookstore purchase
    http://support.apple.com/kb/ht1933
    Refund is an option.
    Best of luck,
    Mario

  • How to Upload and Download Files

    Dear Friends
    I want to write code for Upload and Download file ( Group of Files). Please Guide me the right way I have a few java files and i have compiled that but i donot know how to run that file and i am stranger to java also.
    Please send me reply and sugessest me.
    my email id is [email protected]
    Amogh

    I have write a upload code, but the code can deal with txt onle, it can not deal with bmp or doc, what the matter?
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Upload extends HttpServlet {
         String rootPath;
         static final int MAX_SIZE = 102400;
         public void init(ServletConfig config) throws ServletException
              super.init(config);
         public void doGet(HttpServletRequest request,HttpServletResponse response)
         throws ServletException,IOException
              response.setContentType("text/html");
              PrintWriter out = new PrintWriter (response.getOutputStream());
              out.println("<html>");
              out.println("<head><title>Servlet1</title></head>");
              out.println("<body><form ENCTYPE=\'multipart/form-data\' method=post action=''><input type=file enctype=\'multipart/form-data\' name=filedata>");
              out.println("<input type=submit></form>");
              out.println("</body></html>");
              out.close();
         public void doPost(HttpServletRequest request,HttpServletResponse response)
              ServletOutputStream out=null;
              DataInputStream in=null;
              FileOutputStream fileOut=null;
              rootPath = "C:\\upload\\tmp\\";          //The directory to save the target file.
              try
                   response.setContentType("text/plain");
                   out = response.getOutputStream();
              catch (IOException e)
                   System.out.println("Error getting output stream.");
                   System.out.println("Error description: " + e);
                   return;
         try
              String contentType = request.getContentType();
              if(contentType != null && contentType.indexOf("multipart/form-data") != -1)
                   in = new DataInputStream(request.getInputStream());
                   int formDataLength = request.getContentLength();
                   byte dataBytes[] = new byte[formDataLength];
                   int bytesRead = 0;
                   int totalBytesRead = 0;
                   int sizeCheck = 0;
                   String sourceFileName = "";
                   String targetFileName = "";
                   while (totalBytesRead < formDataLength)
                        sizeCheck = totalBytesRead + in.available();
                        if (sizeCheck > MAX_SIZE)
                             out.println("Sorry, file is too large to upload.");
                             return;
                        bytesRead = in.read(dataBytes, totalBytesRead, formDataLength);
                        totalBytesRead += bytesRead;
                   String file = new String(dataBytes);
                   dataBytes = null;
                   int lastIndex = contentType.lastIndexOf("=");
                   String boundary = contentType.substring(lastIndex+1, contentType.length());
                   //File Content
                   //out.println("File content: " + file);
                   if (file.indexOf("name=") > 0)
                        int fileNameStart = 0;
                        int fileNameEnd = 0;
                        fileNameStart = file.indexOf("filename=\"");
                        fileNameEnd = file.indexOf("Content-Type:");
                        sourceFileName = file.substring(fileNameStart + 10, fileNameEnd - 3);
                        //Source File
                        out.println("Source file: " + sourceFileName);
                   String successPage="";
                   if (file.indexOf("name=\"SuccessPage\"") > 0)
                        successPage = file.substring(file.indexOf("name=\"SuccessPage\""));
                        successPage = successPage.substring(successPage.indexOf("\n")+1);
                        successPage = successPage.substring(successPage.indexOf("\n")+1);
                        successPage = successPage.substring(0,successPage.indexOf("\n")-1);}
                        String overWrite;
                        if (file.indexOf("name=\"OverWrite\"") > 0)
                             overWrite = file.substring(file.indexOf("name=\"OverWrite\""));
                             overWrite = overWrite.substring(
                             overWrite.indexOf("\n")+1);
                             overWrite = overWrite.substring(overWrite.indexOf("\n")+1);
                             overWrite = overWrite.substring(0,overWrite.indexOf("\n")-1);
                        else
                             overWrite = "false";
                        String overWritePage="";
                        if (file.indexOf("name=\"OverWritePage\"") > 0)
                             overWritePage = file.substring(file.indexOf("name=\"OverWritePage\""));
                             overWritePage = overWritePage.substring(overWritePage.indexOf("\n")+1);
                             overWritePage = overWritePage.substring(overWritePage.indexOf("\n")+1);
                             overWritePage = overWritePage.substring(0,overWritePage.indexOf("\n")-1);
                        targetFileName = sourceFileName.substring(sourceFileName.lastIndexOf("\\") + 1);
                        targetFileName = rootPath + targetFileName;
                        //Target File:
                        out.println("Target file: " + targetFileName);
                        int pos; //position in upload file
                        pos = file.indexOf("filename=");
                        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;
                        file = file.substring(pos,boundaryLocation);
                        File checkFile = new File(targetFileName);
                        if (checkFile.exists())
                             if (!overWrite.toLowerCase().equals("true"))
                                  if (overWritePage.equals(""))
                                       out.println("Sorry, file already exists.");
                                  else
                                       //redirect client to OverWrite HTML page
                                       response.sendRedirect(overWritePage);
                                  return;
                        File fileDir = new File(rootPath);
                        if (!fileDir.exists())
                             fileDir.mkdirs();
                        fileOut = new FileOutputStream(targetFileName);
                        fileOut.write(file.getBytes(),0,file.length());
                        if (successPage.equals(""))
                             out.println("File written to: " + targetFileName);
                        else
                             response.sendRedirect(successPage);
                        else //request is not multipart/form-data
                             out.println("Request not multipart/form-data.");
                   catch(Exception e)
                        try
                             System.out.println("Error in doPost: " + e);
                             out.println("An unexpected error has occurred.");
                             out.println("Error description: " + e);
                        catch (Exception f) {}
                   finally
                   try
                        fileOut.close(); //close file output stream
                   catch (Exception f) {}
                   try
                        in.close(); //close input stream from client
                   catch (Exception f) {}
                   try
                        out.close(); //close output stream to client
                   catch (Exception f) {}
    }

Maybe you are looking for

  • Email via report using : SO_NEW_DOCUMENT_ATT_SEND_API1: Function Module.

    Hi, Actually i want to send a mail ( to a yahoo mail address ) using a report, as i came to know that one has to use the above Function Module i started using it. But i am unable to send an e-mail. the report is getting executed and the return code i

  • Arch and preinstalled windows 7 UEFI dual boot troubles

    Hi guys, I have a UEFI pc already with windows 7 on and want to dual boot arch. Problem is the current uefi partition is only 100mb and whenever i try to install a bootloader in the arch install it gives the message 'not enough room on partition'. is

  • NGZ Zone listed as a Server and OS

    Has anybody can accross as issue like this: - Removed and re-installed the agent manully on a NGZ, and within the Ops Center sevrver the NGZ is listed as physical host as well as OS?  Its also listed under the domin that is resides. Other NGZ have wo

  • Web Form Error Message

    I have a very large collection form although it only has 14 "Required fields When I press submit, I get a new page with the following message - ERROR: An error occurred. Your web form must capture customer name and email address. Please fix this issu

  • Paasing an ArrayList as an argument

    In an assignment i am doing i have to pass an arraylist from one swing window to another and i thought i could pass them similar to as you would with methods with the line below: ColBookCar win = new ColBookCar(customers,cars); and then my BookCar wi