How is it posible to get the File name, size and type from a File out the H

How is it posible to get the File name, size and type from a File out the HttpServletRequest. I want to upload a File from a client and save it on a server with the client name. I want to conrole before saving the name, type and size of the file.How is it posible to get the File name, size and type from a File out the HttpServletRequest.
form JSP
<form name="form" method="post" action="procesuploading.jsp" ENCTYPE="multipart/form-data">
File: <input type="file" name="filename"/
Path: <input type="text" readonly="" name="path" value="c:"/
Saveas: <input type="text" name="saveas"/>
<input name="submit" type="submit" value="Upload" />
</form>
proces JSP
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="FileUploadBean" %>
<jsp:useBean id="TheBean" scope="page" class="FileUploadBean" />
<%
TheBean.doUpload(request);
%>
BEAN
import java.io.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletInputStream;
public class FileUploadBean {
public void doUpload(HttpServletRequest request) throws IOException
          String melding = "";
          String filename = request.getParameter("saveas");
          String path = request.getParameter("path");
          PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("test.java")));
          ServletInputStream in = request.getInputStream();
          int i = in.read();
          System.out.println("filename:"+filename);
          System.out.println("path:"+path);
          while (i != -1)
               pw.print((char) i);
               i = in.read();
          pw.close();
}

Thanks it works great.
Here an excample from my code
import org.apache.commons.fileupload.*;
public class FileUploadBean extends Object implements java.io.Serializable{
String foutmelding = "geen";
String path;
String filename;
public boolean doUpload(HttpServletRequest request) throws IOException
     try
     // Create a new file upload handler
     FileUpload upload = new FileUpload();
     // Set upload parameters
     upload.setSizeMax(100000);
     upload.setSizeThreshold(100000000);
     upload.setRepositoryPath("/");
     // Parse the request
     List items = upload.parseRequest(request);
     // Process the uploaded fields
     Iterator iter = items.iterator();
     while (iter.hasNext())
     FileItem item = (FileItem) iter.next();
          if (item.isFormField())
               String stringitem = item.getString();
     else
          String filename = "";
               int temp = item.getName().lastIndexOf("\\");
               filename = item.getName().substring(temp,item.getName().length());
               File bestand = new File(path+filename);
               if(item.getSize() > SizeMax && SizeMax != -1){foutmelding = "bestand is te groot.";return false;}
               if(bestand.exists()){foutmelding ="bestand bestaat al";return false;}
               FileOutputStream fOut = new FileOutputStream(bestand);     
               BufferedOutputStream bOut = new BufferedOutputStream(fOut);
               int bytesRead =0;
               byte[] data = item.get();
               bOut.write(data, 0 , data.length);     
               bOut.close();
     catch(Exception e)
          System.out.println("er is een foutontstaan bij het opslaan de een bestand "+e);
          foutmelding = "Bestand opsturen is fout gegaan";
     return true;
     }

Similar Messages

  • How to get string (specified by line and column) from txt file with labview

    Hi everyone
    How to get string (specified by line and column) from txt file with labview
    thx 
    Solved!
    Go to Solution.

    As far as I know, a text file has no columns.  Please be more specific.  Do you mean something like the 5th word on line 4, where words are separated by a space, and lines are separated by a newline character?  You could the Read from Spreadsheet String function and set the delimiter to a space.  This will produce a 2D array of strings.  Then use index array and give the line number and column number.
    - tbob
    Inventor of the WORM Global

  • The back, forward, reload and stop buttons are greyed out, the address bar stays blank when I go to a website and firefox loads to a blank page, not my home page. There are 3 users on this computer and it only happens on one user.

    Firefox loads to a blank page, not my home page. When I click on the home button it takes me to the home page. The back, forward, refresh and stop buttons are greyed out and not usable. The webpage I am on does not show up in the address bar. If I type something into the address bar, that address stays there no matter what page I go to next.

    Just upgraded to v4. It did NOT fix the problem.

  • Why does the keyboard take over and type c's all across the search box (no hands involved)?

    Why does the keyboard take over and type c's across the search box (no hands involved)?

    There are only three possibilities. Either a dangling hand hitting the c key, or if you have a bluetooth keyboard connected and something is pressing a key, or you have some bad harware.  Eliminate the first two, and if you still have the problem, take it in for service or replacement

  • Hi. In simple language, can you please tell me the best way to protect my important and numerous files - music, images and docs - from being lost; in the event the computer crashes and data is irretrievable?

    I have a lot of photos and music, plus important personal files. In simple terms, can you recommend how I should go about backing these up and ensuring they are not lost through some computer malfunction?
    I need to understand the uses and merits of iCloud, Time Machine and on/off site external drives. I don't really want to invest money, time or new external hardware to achieve this. It can't be too labour intensive, either.
    I have an external drive, which I last backed up perhaps two years ago. It is old, it requires wiring, and it sits next to to the desktop, so would be useless in case of fire (god forbid), say.
    At the same time, I am concerned about cloud storage, and putting personal info and files into anonymous server farms, and the hands of anonymous organisations/people.
    Call me a luddite, but I suspect these are fairly standard concerns, and I can find simple answers with a simple Google search.
    Thanks in advance for your help.

    This is what Apple has to say:
    Report on Government Information Requests
    "... our business does not depend on collecting personal data. We have no interest in amassing personal information about our customers."
    This one concerns iOS, but its approach to privacy is the same:
    http://images.apple.com/ipad/business/docs/iOS_Security_Feb14.pdf
    A couple stories about one Google alternative:
    DuckDuckGo: the plucky upstart taking on Google with secure searches
    DuckDuckGo: The privacy search ruffling Google's feathers
    NSA scandal delivers record numbers of internet users to DuckDuckGo
    Why Traffic To These Google Alternatives Is Soaring
    One of several concerns about Google Chrome, for instance:
    Chrome Bugs Allow Sites to Listen to Your Private Conversations
    Google's Business Model: YOU Are the Product
    "You are not a Google customer. You are a Google product."
    Those aren't just anyone's worthless opinions. Those are also the exact words of a federal magistrate dismissing a case regarding privacy intrusion involving the plaintiff's Android phone:
    "... With little or no revenue from its users, Google still manages to turn a healthy profit by selling advertisements within its products that rely in substantial part on users’ personal identification information (“PII”). As some before have observed, in this model, the users are the real product."
    I understand you didn't ask primarily about Google, but you expressed the very understandable desire for privacy, yet don't seem to mind using Google for search. Those aren't reconcilable sentiments.

  • Setting up the File Name of email Attachment from Received File Name

    Hello All,
    I have to send the Received File in attachment to an Email if there is any exception. Here I can attach the file, but I cannot set the file name of attachment as the Received File Name. Is there anyway of doing this without using custom pipeline component.
    Here I am using the Orchestration and SMTP Adapter.Any help is greatly appreciated.
    Thanks

    It might work if you use a custom pipeline component on your send port and in the Execute method populate the MIME.FileName property of the body part.
    Something like:
    public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
    string filename = inmsg.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties");
    inmsg.BodyPart.PartProperties.Write( "FileName", "http://schemas.microsoft.com/BizTalk/2003/mime-properties", "filename);
    return inmsg;
    You can take reference from similar post here
    SMTP - Setting attachment filename
    Anther good article with MIME is here
    Setting attachment filename with the SMTP Adapter
    For MIME case your SMTP message construct statement would be like below
    multipartMessage.MessagePart_1= InMSG;
    multipartMessage.MessagePart_2="This is message part2 as a string";
    multipartMessage(SMTP.Subject) ="Email From Dynamic Port";
    multipartMessage(SMTP.From) ="[email protected]";
    multipartMessage(SMTP.SMTPHost) ="yoursmypserver.com";
    multipartMessage.MessagePart_2(MIME.FileName) = "Attachment_Name";
    multipartMessage(SMTP.SMTPAuthenticate) =0;
    Thanks
    Abhishek

  • Dynamic sender  file name Pattern and collecting into one file

    Hi Experts,
    Could you please let me know how to achieve below scenario.
    1)     File Directory: TEMP: files: test1,test2,ign1,ign2..etc.
    2)     Get the files of pattern test*
    3)     Received files test1, test2.
    4)     Club contents of file Hemanth1, Hemanth2.
    Ex: test1 contains------REC1
          test2  contains------REC2
    OUTPUT FILE contains REC1,REC2.
    5)     Pass OUTPUTFILE and filenames (test1,test2) to R/3.
    PS: Please dont give references of blogs..I went through most of them could n't finad anything helpful.
    My concern is how to collect files into one file and sending filename pattern..
    Thanks in advance..

    Hi Experts,
    Could you please let me know how to achieve below scenario.
    1)     File Directory: TEMP: files: test1,test2,ign1,ign2..etc.
    2)     Get the files of pattern test*
    3)     Received files test1, test2.
    4)     Club contents of file Hemanth1, Hemanth2.
    Ex: test1 contains------REC1
          test2  contains------REC2
    OUTPUT FILE contains REC1,REC2.
    5)     Pass OUTPUTFILE and filenames (test1,test2) to R/3.
    6) Suppose poling is for 2 minutes..I dont want to read the files which I already read again (I dont want to delete or modify source directory files)
    PS: Please dont give references of blogs..I went through most of them could n't finad anything helpful.
    Thanks in advance..

  • How can I auto export a PDF File using the "Smallest File Size" preset and set the Exported File Name based on information from an Imported PDF?

    Greetings all,
    I am trying to create a script to automate a PDF export process for my company for inDesign. I’m fairly new to inDesign itself and have no previous experience with javascript, although I did take C++ in high school and have found it helpful in putting this code together.
    We have an inDesign template file and then use the Multi-page PDF importer script to import PDF files. We then have to export two version of each file that we import, then delete the imported file and all of the pages to reset the template. This has to be done for nearly 1000 pdf files each month and is quite tedious. I’m working on automating the process as much as possible. I’ve managed to piece together code that will cleanup the file much quicker and am now trying to automate the PDF exports themselves.
    The files are sent to us as “TRUGLY#####_Client” and need to be exported as “POP#####_Client_Date-Range_North/South.pdf”
    For example, TRUGLY12345_Client needs to be exported as POP12345_Client_Mar01-Mar31_North and POP12345_Client_Mar01-Mar31_South.
    There are two templates built into the template file for the north and south file that are toggled easily via layer visibility switches. I need to get a code that can ideally read the #s from the imported Trugly file as well as the Client and input those into variables to use when exporting. The date range is found in the same place in the top right of each pdf file. I am not sure if this can be read somehow or if it will have to be input manually. I can put North or South into the file name based on which template layer is visible.
    I am not sure how to go about doing this. I did find the following code for exporting to PDF with preset but it requires me to select a preset and then type the full file name. How can I set it to automatically use the “Smallest File Size” preset without prompting me to choose and then automatically input some or preferably all of the file name automatically? (If the entire filename is possible then I don’t even want a prompt to appear so it will be fully automated!)
    PDF Export Code (Originally from here: Simple PDF Export with Preset selection | IndiSnip [InDesign® Snippets]):
    var myPresets = app.pdfExportPresets.everyItem().name;
    myPresets.unshift("- Select Preset -");
    var myWin = new Window('dialog', 'PDF Export Presets');
    myWin.orientation = 'row';
    with(myWin){
        myWin.sText = add('statictext', undefined, 'Select PDF Export preset:');
        myWin.myPDFExport = add('dropdownlist',undefined,undefined,{items:myPresets});
        myWin.myPDFExport.selection = 0;
        myWin.btnOK = add('button', undefined, 'OK');
    myWin.center();
    var myWindow = myWin.show();
    if(myWindow == true && myWin.myPDFExport.selection.index != 0){
        var myPreset = app.pdfExportPresets.item(String(myWin.myPDFExport.selection));
        myFile = File(File.saveDialog("Save file with preset: " + myPreset.name,"PDF files: *.pdf"));
        if(myFile != null){
            app.activeDocument.exportFile(ExportFormat.PDF_TYPE, myFile, false, myPreset);
        }else{
            alert("No File selected");
    }else{
        alert("No PDF Preset selected");
    So far my code does the following:
    1) Runs the Multi-Page PDF Import Script
    2) Runs PDF Export Script Above
    3) Toggles the Template
    4) Runs #2 Again
    5) Deletes the imported PDF and all pages and toggles template again.
    It’s close and much better than the original process which was almost 100% manual but I’d like to remove the Preset prompt from the PDF script and have it automatically select the “Smallest File Size” preset. and then if there’s a way to have it auto-fill in the file name so no user input is required at all other than selecting each file to import. (If there’s a way to setup a batch action for the multi-import script that would be even better!)
    Thanks in advance and if there’s anything else I can provide that would help please let me know! Even a nudge in the right direction will be a big help!

    If you hold down the option key, it will typically show the location. Or you can often hit option-return on the file and it will reveal the file in the Finder, instead of opening it.
    Final option is to open it, and just option-click the filename in the toolbar of Preview and it should show you the location.
    It's probably an attachment to an email you've received. If you have Mail set to cache emails and their attachments it'll be stashed in a subdirectory of ~/Library/Mail. Which is fine.

  • Itunes 10.6.1.7 problem: when I change the file "media type" from 'Music' to 'Podcast' the file disapears from ITUNES. I do this via (1) right click, (2) select 'Get Info', (3) select 'options' tab, and (4) change media type. What is the problem?

    Itunes 10.6.1.7 problem: when I change the file "media type" from 'Music' to 'Podcast' the file disapears from ITUNES. I do this via (1) right click, (2) select 'Get Info', (3) select 'options' tab, and (4) change media type. What is the problem?

    Hi Memalyn
    Essentially, the bare issue is that you have a 500GB hard drive with only 10GB free. That is not sufficient to run the system properly. The two options you have are to move/remove files to another location, or to install a larger hard drive (eg 2TB). Drive space has nothing to do with SMC firmware, and usually large media files are to blame.
    My first recommendation is this: download and run the free OmniDiskSweeper. This will identify the exact size of all your folders - you can drill down into the subfolders and figure out where your largest culprits are. For example, you might find that your Pictures folder contains both an iPhoto Library and copies that you've brought in from a camera but are outside the iPhoto Library structure. Or perhaps you have a lot of purchased video content in iTunes.
    If you find files that you KNOW you do not need, you can delete them. Don't delete them just because you have a backup, since if the backup fails, you will lose all your copies.
    Don't worry about "cleaners" for now - they don't save much space and can actually cause problems. Deal with the large file situation first and see how you get on.
    Let us know what you find out, and if you manage to get your space back.
    Matt

  • Need to get all the files, well music and video, from my ipod touch 5th gen to my itunes libary.

    Need to get all the files, (well music and video), from my ipod touch 5th gen to my itunes libary. (So basically sync the other way to normal)
    Laptop hard drive broke so had to buy a new one and obviously now need to sort out my itunes.
    Did try downloading all my purchased stuff onto itunes but it has missed some things off, and there are some files I did not purchase from itunes so need a way of getting them back on there.
    Sure this question has been asked a million times but can't find anything to help me on here so thought I'd ask.
    -Did have a look at going onto the start menu and opening the hidden items thing but couldn't see any reference to ipod or device on it so wasn't sure how to do it that way.
    -On itunes under my device when its connected, the section about manually restoring and backing up, would that help me? Because that says it will manually back up my ipod to my computer then could restore that back up, obviously I don't want to accidnetally get rid of everything on my ipod so didn't want to try that just in case without checking.
    (And yes I have disabled auto sync to device when conncected!)
    Can anyone help me please? Sorry if i've overcomplicated this!
    Thanks:)
    Chris

    Backing up an iOS device will copy some data to a backup file within iTunes, but this excludes all media.  You can also transfer iTunes Store purchases from the iDevice to iTunes but, without using a third-party tool, nothing else.  As long as you do not sync the iPod with your new library, the media that's on it will remain ... for as long as it keeps functioning, is not lost, stolen, eaten by the dog, ...
    You may also have an option to recover your previous library from your old laptop; as long as its hard drive isn't fried, a computer repair store or technician may be able to extract the drive, mount it in an external enclosure, and copy your data to another PC.  Whatever you choose, there is no real alternative to having all your media on your computer, managed by iTunes, and regularly backed up to another device/location.

  • How to extract the size and date from a given file

    Hi,
    I want to extract the size and date of a file (it can be either a video, audio or text file) that the user points to the location of. But I am not sure how. Does Java have an api that can do this? If not is there some other way of doing this? Can anyone help? Thanks in advance.

    Have a look at java.io.File, specifically
    public long lastModified()
    This format returned (I find) is nasty, so then use java.util.Date (or java.sql.Date, look the same on the surface to me) to format it.
    Cheers,
    Radish21

  • I have an iPhone 6 with IOS 8.1.3 and when I use the landscape view in Safari, the bookmark page appears and takes up one half of the screen. How can I get rid of the bookmark page so I can have the whole screen to what I am browsing?

    I have an iPhone 6 with IOS 8.1.3. When I go to the landscape view in Safari, the bookmark page appears and takes up one half of the screen. How can I get rid of the bookmark page so I can use the whole screen to what I am browsing?

    OOPS! Too quick on the trigger to ask that question without trying anything. Sorry. Solved it by touching the bookmark icon.

  • I'm new to Mac. I have an iPhone and a Mac Mini.  My original iTunes was on a Windows computer that crashed.  So, all of my iTunes Music and Movies are gone.  How do I get the movies and music from my iPhone to the new Mac Mini?

    I'm new to Mac. I have an iPhone and a Mac Mini.  My original iTunes was on a Windows computer that crashed.  So, all of my iTunes Music and Movies are gone.  How do I get the movies and music from my iPhone to the new Mac Mini?

    If you still have the crashed Win computer, you may be able to recover your music and movies from the hard drive. If you have a friend with a hard drive USB connection kit and a PC, they should be able to help.  Otherwise, check locally for computer services that might do that for you (I think Best Buy Geek Squad may be able to help). If the drive itself is in good shape, it shouldn't be too expensive. 

  • ITunes will no longer play my music, all the albumss are there but it if I click on a song to play it I get a message saying " The song (name of song) could not be played because the original file coul not be found. Would you like to locate it."

    iTunes will no longer play my music, all the albumss are there but it if I click on a song to play it I get a message saying " The song (name of song) could not be played because the original file coul not be found. Would you like to locate it."

    You get this message because  iTunes can’t find the file. This can happen for a number of reasons:
    The song file or a folder in its path was renamed
    The song file or the folder it is in has been moved
    The song file has been deleted
    The device containing the song files e.g. external drive is not accessible or the drive letter has changed.
    Do any of these aply to you?

  • I'm trying to update my daughter's Ipad2 to the new IOS 8 and it's got stuck on the connect to ITunes display.  We don't have a computer to connect it to and it's never been connected to one.  How do I get past this?

    I'm trying to update my daughter's Ipad2 to the new IOS 8 and it's got stuck on the connect to ITunes display.  We don't have a computer to connect it to and it's never been connected to one.  How do I get past this?

    You can try a soft-reset of pressing and holding both the home and sleep buttons for 10 to 15 seconds so that it reboots, but you are likely to get the same screen. If it does then it will need to be connected to a computer's iTunes so that it can be reset back to factory defaults - do you have a friend with a computer with iTunes installed on it, or is there an Apple store nearby that you could try going to (if there is then preferably make a Genius Bar appointment at it, or don't go at a busy time) ?
    Has she been backing up to the cloud ? If she has then she should be able to restore to that. If not then what she can redownload for free from the stores will show in the Purchased tabs in the store apps.

Maybe you are looking for

  • Can no longer use HP device manager to scan to OCR

    Today I tried to use the HP device manager with an HP J4550 all in one to scan a document to OCR.  Not only could the scanner not be found, but the HP device manager also crashed...  I used to be able to do this prior to upgrading to Lion.  Is there

  • Word Wrap form labels?

    How can I get a long form label to word wrap instead of being on one long line?

  • System file deletion to boot in Lion?

    What I would like to know is what system file can I delete from the system when booted from another partition so I can boot up in Lion. Lion locked up when I had ten applications open with a multiple windows and I had to do a HARD SHUT DOWN. Now ever

  • Created Items need a Heading Template

    I have created 3 items with labels that need to be put into some type of style template. When you create a report you can choose a report template 2, standard, but if you create items that are placed into that same region they are not part of that st

  • Thinking of getting Infinity

    Hi all,I'm new to the forum and am thinking of getting Infinity,I've checked my phone number and it said I could get a max of 19.8 mb down & 5mb up.Im currently with Sky and get 3mb down max! Will it be likely that I get anything like the estimate or