Why do my file is stored and has the correct dimension but I cannot open it

hi,
I want to store an image from an inputStream to my harddisk. The created file (image) has the same dimensions of the original image (8kb), but I cannot open it with photoshop or other image editors. Something is wrong in the data... can you give me some tips ?
thanks
File outputfile = new File("/Library/Tomcat/webapps/ROOT/WEB-INF/classes/saved2.png");
          try {
               //File f=new File("outFile.java");
               //InputStream inputStream= new FileInputStream("InputStreamToFile.java");
               OutputStream out=new FileOutputStream(outputfile);
               byte buf[]=new byte[1024];
               int len;
               while((len=inputStream.read(buf))>0)
                    out.write(buf,0,len);
               out.close();
               inputStream.close();
               System.out.println("\nFile is created");
          catch (IOException e){
          }

I've solved it with this code:
InputStream inputStream = req.getInputStream();
               BufferedImage img = ImageIO.read(inputStream);
               File outputfile = new File("/Library/Tomcat/webapps/ROOT/WEB-INF/classes/saved2.png");
               //storing the image to file system.
               if (outputfile.isDirectory()) {
                    ImageIO.write(img, "png", outputfile);
               } else {
                    outputfile.mkdirs();
                    ImageIO.write(img, "png", outputfile);
          } catch (Exception e) {
               System.out.println(e.getMessage());
          }

Similar Messages

  • HT204266 my ipad says "connexion a l'iTunes Store impossible" when I click on the App Store icon. I have internet connection, I can access to my emails and use the safari. But I cannot open App Store either Itunes.

    my ipad says "connexion a l'Itunes Store impossible" when I click the App Store button. So, I cannot have access to the Apps. I have internet connection and I can use my emails and the safari. Please advise.

    Try this:
    1. Settings>General>Date & Time>Turn off set automatically
    2. Set date one year ahead
    3. Go back to iTunes and try again.
    4. You will get the same error.
    5. Go back to settings general date and time and turn back on 'set automatically'
    Try connecting to iTune Store again.

  • HT1657 I rented a movie on Itunes last night and I watched half of it before falling asleep. Today I tried to open the movie and watch the last half but I cannot find it. It has been less than 24 hours since I rented it. Where can I find the movie?

    I rented a movie on Itunes last night and I watched half of it before falling asleep. Today I tried to open the movie and watch the last half but I cannot find it. It has been less than 24 hours since I rented it. Where can I find the movie?

    I found my answer in another Thread and it worked... so for anyone who needs it, here it is:
    https://discussions.apple.com/message/19134562#19134562
    Had the same problem and spoke with Apple Support. They had me reset the System Management Controller:
    Shut down the computer. With the computer off, on the left hand side of the keyboard press shift+control+option along with the power button simultaneously and release. Wait 5-10 seconds and restart the computer.
    This solved my problem and I was immediately able to purchase, download, and play an HD movie from iTunes w/o any error message.

  • I am trying to import my libary onto a new computor the file, my libarary that is, is in my music and in the itunes folder but it doesnt open up when l open itunes

    i am trying to import my libary onto a new computor, the file, my library that is, is in my music and in the itunes folder but it doesnt open up when l open itunes would appreciate some help with the import cheers

    Hey samanthaluca,
    Sounds like you want to move your music library to a new computer. I'd follow the steps in this article from the begining to make sure the import goes smoothly:
    iTunes: How to move your music to a new computer
    http://support.apple.com/kb/HT4527
    Cheers,
    Delgadoh

  • I need to update specific records(of variable lengths) in a file. I can get the correct record but when I update it(add info), it overwrites part of the record following it. I am using labview 6.0

    I need to update specific records(of variable lengths) in a file. I can get the correct record but when I update it(add or change info), it overwrites part of the record following it. I am using labview 6.0. I need to be able to insert information into the middle of a file without disturbing the data before and after

    It's hard to give more specifics without more detail, but in general you're going to need to read in the entire file, split it into three pieces (everything before the record of interest, the record itself, and everything after the record of interest), modify the record, reassemble the three pieces in proper order, and write the whole thing back to the file.Of course if the file is very large you might not want to actually implement it this way, but conceptually at least, this is what you are looking at.If this file some sort of proprietary format?Mike...PS: this type of issue is why I really like databases...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Trying to restore after getting a new hard drive.  I can see the backup on the Time Capsule and on the correct date but it is Greyed out.  That is it wont let me open it and restore the machine.  Have tried also Migration Assistant, no luck.

    Trying to restore after getting a new hard drive.  I can see the backup on the Time Capsule and on the correct date but it is Greyed out.  That is it wont let me open it and restore the machine.  Have tried also Migration Assistant, no luck.

    https://discussions.apple.com/thread/5210788?tstart=0
    At startup hold down the Command+Option/Alt+r keys until you see a globe on the screen. Then use disk utility to partition and format the drive HSF+ and then select Reinstall Mac OS X. whatever version of OS X that originally came on your system will be installed and then you can upgrade back to Mavericks.

  • Trying to start my IMac click on my admin icon and enter the correct password but then flashes to white screen and back to sign in, my desktop wont come on ... help!!!!

    Trying to start my IMac click on my admin icon and enter the correct password but then flashes to white screen and back to sign in, my desktop wont come on ... help!!!!

    Boot to the Recovery HD:
    Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
    When the menubar appears select Terminal from the Utilities menu. Enter resetpassword at the prompt and press RETURN. Follow instructions in the dialog window that will appear.
    Or see Reset a Mac OS X 10.7 Lion Password and OS X Lion- Apple ID can be used to reset your user account password.

  • HT5622 I have incorrectly entered an email address that is not valid.  I have requested the change to the correct email but if cannot verify it as the verification email is being sent to the email address that I entered incorrectly and is invalid.  Help!

    I have incorrectly entered an email address that is not valid.  I have requested the change to the correct email but if cannot verify it as the verification email is being sent to the email address that I entered incorrectly and is invalid.  Help!

    Hey Givemepaperandapen,
    Thanks for using Apple Support Communities.
    For more information, take a look at:
    Apple ID: Associating and verifying email addresses with your Apple ID
    http://support.apple.com/kb/he68
    How to edit or change your Apple ID and primary email address
    Have a nice day,
    Mario

  • The radio is not working in my ipod nano, and has the correct zone, how can I make it work?

    I bought the new Ipod nano, and the radio is not working. I live in the USA, and has being setting in "America" zone, but is not working!! I plugged the headphones, and I tried in different places, and I not working!!!
    What could I do?

    Check if the headphones are inserted all the way in till you hear a click. Hope this helps!

  • I bought and paied the Creative Cloud but when I open Photoshop appears the message: "continue the trial". Why?

    I bought and paied the Creative Cloud (€19 por month) but when I open Photoshop appears the message: "continue the trial". Why?

    Sign in, activation, or connection errors | CS5.5 and later
    Mylenium

  • HT1725 I purchased several books from itunes and on my iphone it shows the book cover, but I cannot open them.  There is a solid black line on each cover.  Any suggestions?

    I purchased several books but on itunes but cannot open them on my iphone 4S.  I purchased one without problem.  However, the next several appear in my library but have a solid black line on the cover as though they haven't downloaded.  When I check my itunes account for possible downloads, it shows everything has been done.  Any suggestions?

    Could you take a screenshot of this line?
    Press home and sleep button at the same time I believe.

  • Every time i try to open itunes to update apps for iphone 4s i can never get it to open, i went to command prompt and did the netsh winsock reset, still cannot open itunes

    i cannot open itunes to update apps on my iphone. i did the command prompt-netsh winsock reset, still cannot open itunes.

    Try following steps and test one at a time:
    1. Check to see if this file APSDaemon.exe is the problem here.
    Close your iTunes.
    Press Ctrl-Alt-Del key and choose Task Manager. In the "Processes" Tab, select the file APSDaemon.exe and click End Prosses button, then close the task manager window.
    Now open itunes and see if it is working?
    If that works, to prevent having to do the same process everytime you restart Windows, go to. START button, type in
    MSCONFIG
    Hit ENTER
    Click STARTUP Tab, Uncheck "Apple Push", click OK.
    Restart Windows.
    2. If that fails or you don't see ApsDaemon.exe in the Processes, refer to following article to remove SC files:
    http://support.apple.com/kb/TS2363
    3. If that fails, repair or reinstall your Quicktime. START / CONTROL PANEL / ADD N REMOVE PROGRAMS / hightlight QUICKTIME, click CHANGE or UNINSTALL then REPAIR.

  • My mac mail is asking for my password and its the correct one, but it still does not want to connect to the mail? how do i fix this?

    It's asking for a password, i'm putting in the correct one and it's still not working. it says mail cant connect to the account "...."
    please help!

    If you've activated 2-step verification, you need to generate an application-specific password in your Google account and enter it instead of the login password you use on the website.

  • I have a PowerPC G4. Firefox 5 for Yahoo says that I meet the requirements. But I cannot open the Firefox.app on my computer. Why not? Thanks

    I was able to download Firefox 5. When I transferred it to my applications folder, it states that I cannot open, because my architecture doesn't support it. Why doesn't it state that when I looked up the minimum requirements? According to that, I should be able to use it.

    Beginning with Firefox 4, Macs must have an Intel x86 processor; your system is a PPC Mac.
    *System Requirements: [https://www.mozilla.org/en-US/firefox/4.0/system-requirements/index.html Firefox 4], [https://www.mozilla.org/en-US/firefox/5.0/system-requirements/index.html Firefox 5], [https://www.mozilla.org/en-US/firefox/6.0/system-requirements/index.html Firefox 6], [https://www.mozilla.org/en-US/firefox/7.0/system-requirements/index.html Firefox 7]
    The good news is that Firefox 3.6.23 still supports the PPC Mac architecture. The bad news is that support for the Firefox 3.6.x series is likely to end in the first quarter of 2012.
    *Download Firefox 3.6.23: https://www.mozilla.org/en-US/firefox/all-older.html
    *Installing Firefox on a Mac: http://support.mozilla.com/en-US/kb/Installing+Firefox+on+Mac
    *System requirements: [https://www.mozilla.org/en-US/firefox/3.6/system-requirements/index.html Firefox 3.6.x]
    You can try the third-party product '''''TenFourFox''''' that supports PPC Macs. The product is based on Firefox released versions. All support is provided by the developer, not by this site:
    *Home page: http://www.floodgap.com/software/tenfourfox/
    *Developer's blog: http://tenfourfox.blogspot.com/
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''

  • Filename after scanning has the correct month but the wrong day

    is there a way to change the default settings and or correct the date/name of a scanned document. The file name of the scanned document reflects the scan profile plus the year...month..day...hour(in military)...minute...second. The day is incorrect. What can be done to correct this. The computer time is correct.
    I have tried two separate scanners with the same results. thanks

    This is NOT RESOLVED and is a BUG (is there a better place to post a bug?). I will explain the issue and how to duplicate it.
    Adobe Acrobat X Pro 10.0.1
    When scanning to PDF via an action the file name is incorrectly generated one day ahead of the current.
    Example: A file scanned in today (03/01/11) shows the following filename:
    Scans_201132201258
    The file name structure breaks down like this:
    (Scans=name of action used to generate scan)_(2011=year)(3=month)(2=INCORRECT DATE / current date +1)(201258=20hrs 12min 58sec)
    Here the EXACT steps I used to create this issue:
    File > Create > PDF from Scanner > Configure Presets
    Options > Select my scanner
    Presets: Autodetect Color Mode
    Optimize Scanned PDF checked (probably not important to issue replication)
    Make Searchable checked (probably not important to issue replication)
    Save
    File > Action Wizard > Create New Action
    Starts with: A Scanned Document > Autodetect Color Mode
    No Steps
    Save to: A folder on my computer
    Options box to the right of Save To selection (set to default settings)
    Keep original file names checked
    Save File(s) as Adobe PDFs checked
    Overwrite existing files checked
    Saved action as 'Scans'
    File > Action Wizard > 'Scans'
    File scans and opens with filename incorrect

Maybe you are looking for