Results 1 to 6 of 6

Thread: File manipulation !!!

  1. #1

    Default File manipulation !!!

    hi all ..

    actually my requirment is to read a user selected file ( csv) .. do some operation and write the results into a new file to the server ...

    can any one help me how to do this ..

    any help will be greatly appreciated ...

    thanx in advance ...

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    This is really a general programming question rather than a Spring question. You might want to look for file manipulation libraries.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3

    Default

    thanks for the reply ...

    actually i think some uploading of file is required before programming with libraries ..

    my quiestion is whether i need to physically copy the file to server side before doing some file operations on it ...

    or what to do in such a situation ...?

    sorry for my bad english

    thanx again

  4. #4
    Join Date
    Feb 2005
    Posts
    8

    Default

    <!—test.jsp >
    <FORM name='person' method="POST" enctype="multipart/form-data" >
    <table>
    <tr>
    <th width='20%' align='right'>Import File</th>
    <td>
    <input type="file" name="importFile">
    </td></tr>
    </table>
    </form>



    /**
    * TestForm.java
    */


    import org.apache.commons.fileupload.* ;

    public class TestForm extends SimpleFormController {

    /** Method used to search for owners renders View depending on how many are found */
    protected ModelAndView onSubmit(
    HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
    throws Exception {


    // Create a new file upload handler
    DiskFileUpload upload = new DiskFileUpload();

    // Parse the request
    List /* FileItem */ items = upload.parseRequest(request);
    // Process the uploaded items
    Iterator iter = items.iterator();
    while (iter.hasNext()) {
    FileItem item = (FileItem) iter.next();
    logger.info("importFile name=" + item.getFieldName());
    if("importFile".equals(item.getFieldName())){
    logger.info("importFile=" + item.getName());
    readFileContents(item);
    break;
    }
    }

    return new ModelAndView(new RedirectView("home.htm"));
    }

    /**
    * read the content of import file
    *
    * @throws IOException
    */
    public void readFileContents(FileItem item ) throws IOException {
    //File file = new File(fileName);

    String thisLine;
    StringBuffer content = new StringBuffer();
    String filecontents = "";

    //
    //logger.info("file exist .." + fileName);
    InputStream fin = item.getInputStream();

    //JDK1.1+
    BufferedReader myInput = new BufferedReader
    (new InputStreamReader(fin));
    // JDK1.02
    // DataInputStream myInput = new DataInputStream(fin);
    while ((thisLine = myInput.readLine()) != null) {
    //thisLine = doStringReplace(thisLine);
    logger.info("thisLine =" + thisLine);
    content.append(thisLine);
    content.append("\n");
    }
    fin.close();

    //logger.info("file content =\n" + content);
    }
    }

  5. #5
    Join Date
    Jun 2005
    Posts
    1

    Default Doesn't work for mixed forms...

    I have a form that combines input type=file and type=text elements. When I try to do typical request.getParameter calls, I get nulls back on items that work when the form enctype is default...

  6. #6
    Join Date
    Feb 2005
    Posts
    8

    Default Re: Doesn't work for mixed forms...

    Quote Originally Posted by cglenn
    I have a form that combines input type=file and type=text elements. When I try to do typical request.getParameter calls, I get nulls back on items that work when the form enctype is default...
    i got the same problem. i use
    fileitem.getString()
    to get the values

    for complex form and database processing, i prefer Struts forms and direct jdbc satatement

Similar Threads

  1. Replies: 2
    Last Post: Apr 12th, 2012, 09:34 AM
  2. Replies: 5
    Last Post: Mar 17th, 2010, 04:32 AM
  3. Deferred file upload
    By Thomas Matzner in forum Web
    Replies: 4
    Last Post: Sep 30th, 2005, 12:06 PM
  4. Can't find the configuration file in WebLogic...
    By anagnost68 in forum Container
    Replies: 1
    Last Post: Sep 8th, 2005, 01:00 AM
  5. Replies: 2
    Last Post: Nov 15th, 2004, 07:22 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
  •