Converting a file to string and then, the string to a file

I need to send a File (a JPG file) as String (inside a XML document).
After this, i want to write the String representing the file (reading the XML document) as a File on my disk (making a JPG).
Can anybody help me ???
Thanks in advance !!

I found this in the forum, the author was brianlmartino1
and it works perfectly.
Thank you !!
import java.io.*;
import org.apache.soap.encoding.soapenc.Base64;
public class FileUtils {
static public void main(String args[]) throws Exception {
System.out.println("-- go !!!!");
// get input binary source
File file = new File("c:\\temp\\file.JPG");
BufferedInputStream bis = new BufferedInputStream(new
FileInputStream(file));
int bytes = (int) file.length();
byte[] buffer = new byte[bytes];
int readBytes = bis.read(buffer);
bis.close();
// encode binary source
String encodedString = Base64.encode(buffer);
// decode String source and save the file to the disk
byte[] buffer2=Base64.decode(encodedString);
File file2 = new File("c:\\temp\\fileNew.jpg");
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file2));
bos.write(buffer2);
bos.close();
System.out.println("-- ready !!!!");
}

Similar Messages

  • HT1473 I click "add file to library" and then the song i want, but it doesn't come up

    Im really POed at the new iTunes on so many levels. first, the iCloud makes all songs i bought when i was 11 and deleted when i was 13 again. me and my little sister share the same account, but we have different computers so we don't have each other's song. now, thanks to iCloud, we do. i do not want carrie underwood or justin bieber, abd she doesn't want david bowie and led zeppelin. right now, the icloud isn't working, which is fine right now, but it's not right.
    ok, about "adding music and other content to iTunes." you used to be able to drag a file from your documents to your library and it would be copied onto it. i am under the impression that that isn't the case anymore. I've tried a billion times and it hasn't worked. even when im on the led zeppelin section of my library and i drag "over the hills and far away" it won't budge; there's still only 6 albums and 10 songs. so i clicked "add file to library" and then the song i want, but it doesn't come up. and i did this a zillion times with a bunch of different songs, and nothing.
    another problem is that the files are screwy. "houses of the holy" is on the album physical graffiti, not houses of the holy. if i edit the song's info to physical graffiti, all the other songs that are supposed to be on houses of the holy go into physical grafitti. when i go to song info, they still say houses of the holy. i just tried changing it again, and now all my led zeppeling albums are labeled houses of the holy. WHAT IS THIS MADNESS!?!?!?!?!
    #NewiTunesSucks

    Go to edit-preferences-advanced-
    uncheck 'keep itunes media folder organised'
    Then  make changes and see if itunes keeps the new info...
    But warning! if you allow iTunes to organise your files in the future  these change will be undone I believe.

  • Converting Image to Byte Array and then to String

    Hi All...
    Can anyone please help me. I have got a problem while converting a Byte array of BufferedImage to String.
    This is my code, First i convert a BufferedImage to a byte array using ImageIO.wirte
    public String dirName="C:\\image";
    ByteArrayOutputStream baos=new ByteArrayOutputStream(1000);
    BufferedImage img=ImageIO.read(new File(dirName,"red.jpg"));
    ImageIO.write(img, "jpg", baos);
    baos.flush();
    byte[] resultimage=baos.toByteArray();
    baos.close();
    Then i tried to convert this byte array to a string
    String str=new String(resultimage);
    byte[] b=str.getBytes();
    This much worked fine. But when i reversed this process to re-create the image from that string. i found the image distroted.
    BufferedImage imag=ImageIO.read(new ByteArrayInputStream(b));
    ImageIO.write(imag, "jpg", new File(dirName,"snap.jpg"));
    I got this snap.jpg as distroted.
    Please help me i have to convert the image to a string and again i have to re-create the image from that string.

    To conver the bytearray to string use base64.encoding
    String base64String= Base64.encode(baos.toByteArray());
    To convert back use Base64.decode;
    byte[] bytearray = Base64.decode(base64String);
    BufferedImage imag=ImageIO.read(bytearray);

  • Pages works with all other docs, except the one I need to work on.  From my downloads folder I can preview the entire file, however whenever I try to open it, i get the "opening" pane filled to ~90% and then the SBBOD.  Only file it does this on...help??

    From my downloads folder it recognizes the file as a Pages document, I can preview the entire document, but I try to open the file in multiple ways (from right click, to open from preview, from inside pages) and it refuses to open.  The "opening" prompt comes up, fills ~90% and then I eventually get the SBBOD.  It will fail out if given long enough to think it through or i need to force quit.
    OS- 10.7.5
    Pages: downloaded from App store when i purchased my mac mini last fall. fresh update.

    Since it has always been very basic to backup your computer and all it's data, Apple provides no way for you to transfer music from your iPhone back to your computer.  As you know, you can re-download all iTunes purchases, but music that you ripped yourself you'll have to just re-rip again.
    You can try and find 3rd party applications that might help you.  I'm sure you'll pay, however.
    Let this be a very important lesson learned.
    Best.

  • Every time I try to download Firefox, it says the file is corrupt and then the download window disappears.

    I can't download Firefox. Every time I try a popup says the file is corrupt and the download goes away. What do I need to do to make the download work?

    Download a fresh Firefox copy and save the file to the <u>Desktop</u>.
    * Firefox 6.0.x: http://www.mozilla.com/en-US/firefox/all.html
    * Uninstall your current Firefox version.
    * Do not remove personal data when you uninstall the current version.
    Remove the Firefox program folder before installing that newly downloaded copy of the Firefox installer.
    * It is important to delete the Firefox program folder to remove all the files and make sure that there are no problems with files that were leftover after uninstalling.
    Your bookmarks and other profile data are stored elsewhere in the Firefox Profile Folder and won't be affected by a reinstall, but make sure that you do not select to remove personal data if you uninstall Firefox.
    * http://kb.mozillazine.org/Profile_folder_-_Firefox
    * http://kb.mozillazine.org/Profile_backup

  • Find a specific character in an input string and getting the string after if

    Hello,
    my requirement is as such, lets say we have an input string ABHISHEK #1234, or BOMBAY 123 #235,
    i need to find if the character string has # in it,, if yes pick all the numbers after # .
    in the above example, i need output as 1234 and 235
    and if any non numeric values after # set a flag
    please help me in this.
    regards
    Abhishek

    Hi Abhishek,
    This can be done in BODS using below settings in file format (only if your source is flat file):
    Below is the source file data :
    abcd#1234,Bombay#23456
    By using this file format setting, you should be able to get all the numbers in one column which you can use futher and you can verify this columns data by using "is_valid_int", not null function in BODS.
    I think it should give you solution.
    Thanks,
    Tanvi

  • Isolating capitals in Strings, and altering the strings.

    Dear CodeWizards,
    My friend asked me to help him write some code for his website he's making. I'm a freshman in college, in elementary Java Programming, so I thought I could do it. Turns out I'm wrong, we haven't even touched on the stuff he wants me to do, and I would like your help if you could lend me a hand.
    Here's what he emailed me:
    "Hey Jason,
    You're in that computer programming class, right? Well I am making this website, and it has some little games on it and stuff. Part of it I don't know how to figure out. I want the person to input a name of an organization. Then I want the program to take all the capital letters, and put asterisks around them, then re print what he person says with the asterisks in there, as well as with the rest of the letters capitalized. Then I want it to print out just the capital letters in the asterisks, like an acronym. Also if there is anything in Parenthesis, i want it disregarded. Heres an example:
    What is the name? Midgets Riding UniCycles (How Fast Can They Go?)
    The name is: *M*IDGETS *R*IDING *U*NI*C*YCLES
    The Acronym is: MRUC
    Thanks,
    Jim"
    Anyway fellas, I'm in over my head here. I was told by an upperclassman this should be easy, but what upperclassman is going to help out a freshman, lol. If someone has a spare moment and they could whip this up, then I would appreciate it. If not, any help would be great. I am without direction. Sorry for being such a newb... Thanks again guys'n'gals.
    Jason

    What have you managed to do so far?
    Here's some general advice:
    Read the assignment text well, send email to your instructor about the parts
    that are not clear, and start doing it. Only when you encounter a problem that
    you can't overcome by reading your notes, the Java tutorial, or the
    documentation of standard classes come back here and ask a specific question
    with a clear description of the problem you are having with some source code,
    what you want it do, what it is doing instead, and possible error message.
    Java tutorial: http://java.sun.com/docs/books/tutorial/
    Documentation of standard classes: http://java.sun.com/j2se/1.5.0/docs/api/
    Examples of how to use them: http://javaalmanac.com

  • First the text and then the icon in JButton

    Hi,
    I want to create a button with a String followed by an icon. When I do
    JButton aButton = new JButton("Select", new MetalComboBoxIcon());
    It puts the icon first and then the string. I want to a create a button that looks like JComboBox.
    How would I do this?
    thx.

    setHorizontalTextPosition(SwingConstants.LEFT).
    Check out http://java.sun.com/j2se/1.3/docs/api/javax/swing/AbstractButton.html#setHorizontalTextPosition(int).
    Good luck,
    -- Scott

  • I downloaded mountain lion and then the new office suite (word, ppt, excel) but now when I try to display one of my ppt's it says 'ppt cannot open the file...the file may be corrupt, in use, not a type recognized by ppt etc.." how can I fix it?? HELP

    I downloaded mountain lion and then the new office suite (word, ppt, excel) but now when I try to display one of my ppt's it says 'ppt cannot open the file...the file may be corrupt, in use, not a type recognized by ppt etc.." how can I fix it?? HELP

    Did you try to open teh fle by double-clicking its icon? If the file was made with an older version of Office, you may get that message. Try opeing PP and, from its "File" menu, see if you can open the ppt. I've foundthat often gets around that message and then yo ucan save the file from the newer version.
    If that doesn't work, consider asking in the Microsoft Office: Mac forums here:
    Office for Mac forums
    PowerPoint is not an Apple product and it seems a lot of people around here avoid Office.

  • Trying to drag pdf files i have and combine them into one pdf file in the account i just purchased with Adobe. when i drag a pdf file over Adobe doesn't accept it. says it can not convert this type of file. but it is an Adobe file. Do I need to change it?

    Trying to drag pdf files i have and combine them into one pdf file in the account i just purchased with Adobe. when i drag a pdf file over Adobe doesn't accept it. says it can not convert this type of file. but it is an Adobe file. Do I need to change it in some other form befor dragging it?

    Hello djensen1x,
    Could you please let me know what version of Acrobat are you using.
    Also, tell me your workflow of combining those PDF files?
    Please share the screenshot of the error message that you get.
    Hope to get your response.
    Regards,
    Anubha

  • I set up my new computer using the apple ID i always use, and then later migrated all my files from my old mac book to the same new one, but under a different user (same ID). how do i consolidate the two users on my new mac book?

    i set up my new computer using the apple ID i always use, and then later migrated all my files from my old mac book to the same new one, but under a different user (same apple ID). how do i consolidate the two users on my new mac book?

    Well if you use the Finder Go menu to Computer, a window opens up double click on your boot drive and then on Users folder, open the other user folder and open Public and drop your files into DropBox
    When you do this it will copy them and change the permissions and user assigned to it, so log into the other user and place them into your respective normal folders.
    Once you have all your files over and don't need the old user, use System Preferences > Accounts to delete it if you wish, however it's good two Admin accounts on the machine in case something bad happens in the other. Some people for security reasons on use a Standard account for most uses and a emergency Admin account.
    One can still do most Admin things in Standard user.

  • I am looking for an application that would allow me to open a word doc, and take notes in the .doc using a stylus pen.  I'd then like to convert those notes to text, and then be able to copy / paste those notes into an email.  Does this app exist?

    I am looking for an application that would allow me to open a word doc, and take notes in the .doc using a stylus pen.  I'd then like to convert those notes to text, and then be able to copy / paste those notes into an email.  Does this app exist?  It seems like we were doing these same types of things with Palm Pilots years ago, one would think this would work with iPads?

    I don't believe it will open a Word document, but Writepad allows for handwritten conversion of notes to text and then to email. Might help you some of the way...

  • I tried to rename a file, it gave me an error message (can't remember the number - 43??) and then the file disappeared from the original folder. When I do a search, the file comes up under the new name, but it does not show a path, and even though preview

    I tried to rename a file, it gave me an error message (can't remember the number - 43??) and then the file disappeared from the original folder. When I do a search, the file comes up under the new name, but it does not show a path, and even though preview shows the contents, I can't open the document (Powerpoint) and I can't move the document. I tried "Copy" and paste but it doesn't work. I tried "Share" with Airdrop and iChat, but the file is inaccessible. When i try to rename the file, it says the filename is too long.
    When I try to open it, it says the alias is not good, and asks if I want to fix the alias. I'm afraid to do that and lose all access to this document.
    Right now, it feels like a ghost document - it is on the computer intact, but it is in an undisclosed location and inaccessible.
    Please help!!

    I was able to resolve this by repairing permissions, even though no permissions error was listed specifically for that file.
    I could also have recovered it through Time Machine, but I'm interested in knowing how not to have this happen again!
    I was afraid of rebooting and possibly losing track even of the ghost.
    I did not try EasyFind - I'll keep that in mind next time.
    Thanks for all the comments.

  • Tried to "Open As" in PS a NEF file I modified in LR.  Got the following error message:  "Could not complete your request because the file format module cannot parse the file."  I can "Open" the file in PS, but then the changes I made in LR (and saved in

    Tried to "Open As" in PS a NEF file I modified in LR.  Got the following error message:  "Could not complete your request because the file format module cannot parse the file."  I can "Open" the file in PS, but then the changes I made in LR (and saved in the associated meta data file with the "Control S" command) are not applied to the opened PS file.  HELP!

    If you are working with a file you modified in Lightroom, you should go to the Lightroom Photo menu and choose Edit in... and the version of Photoshop you want to open it in.
    There a dialog will ask if you want to transfer the LR settings you made to your photo when you open in Photoshop.
    Gene

  • HT1343 On my 4 1/2 year old Macbook I could select multiple files  by highlighting a file and then moving cursor over a file lower in the list, and pressing shift-control-click. I can't do that in now with Mac Pro.  What am I doing wrong?

    ghlighting a file and then moving cursor over a file lower in the list, and pressing shift-control-click. I can't do that in now with Mac Pro.  What am I doing wrong?

    Holding down the control key will invoke "right-click."
    Depending on the View, holding down Shift will with either toggle the selection (Icon View), or it will make a continuous selection from the previous selection (List View or Column View).
    The only way to make a continuous selection in Icon View is to drag out a selection marquee around or through the icons.
    I can't remember the behavior of previous OS's.

Maybe you are looking for

  • Since I upgraded to Moutain Lion I'm dealing with wifi problems : no connection or random connection

    Since I upgraded to Moutain Lion I'm dealing with wifi problems : no connection or random connection. With  OS X Lion wifi was OK.

  • Related to NetWeaver

    Hi, Actually My Problem is JSPs are not pre-compiled on NW during deployment as done by WAS. This leads to high load times when UI is visited for very first time. It can lead to doubting application UI performance.So help me if any solutions for that

  • PDF colors wrong on ipad/iphone HELP!

    When exporting PDFs from InDesign they look great on the computere but there is a HUGE color shift on the Ipad/Iphone. The main color is a rich purple which turns into neon blue on the iphone/Ipad. Through research I have found that iphones/ipads sho

  • Error when Combining Files (Acrobat XI & Office 2010)

    I have a user who is getting an error every time she tries to combine files on her computer. Pdfs will combine just fine. Pdf + MS Office file types fail. Combining two MS Office file types fail. A side issue, maybe related, is that the Acrobat tab i

  • Populating graph in excel using ole

    Hi All, I am able to populate the graph from abap into excel using OLE. But I am not able to take x-axis and y-axis according to my requirement, its taking by its own as default. please see the below code: <b>CALL METHOD OF GS_EXCEL 'Cells' = GS_CELL