How do you write any kind of content you want into a new file using Java?

I know this is extremely basic, but I have absolutely no idea how to do this!
How can I create a brand new file on my machine, this new file containing literally ANYTHING I want: String content; Image content, Excel content, Whatever content.. literally anything on the planet I can come up with..??
I have tried everything I can think of to no avail and have exhausted every online tutorial I could find both here and via Google, to no avail. I can't figure it out, and this is all I have so far:
* FileDownloader.java
* Created on January 10, 2007, 3:47 PM
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package FileTools;
import java.io.*;
import java.net.*;
* @author ppowell-c
public class FileDownloader {
    public static void download(URL url, File file) throws IOException {
        InputStream in = url.openStream();
        FileOutputStream out = new FileOutputStream(file);
        byte[] b = new byte[1024];
        int len;
        while((len = in.read(b)) != -1) {
            out.write(b, 0, len);
        out.close();
    public static void download(String path, File file) throws IOException {
     download(new URL(path), file);
    public static void download(String path, Object contents) throws IOException {
     ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(path));
     out.writeObject(contents);
     out.close();
}This code fails to download contents into a new file in the case whereby I want to create a new .ico Icon file with the contents from ImageIcon.getImage() as an example, which is what I want to do right now.
Thanx
Phil

beyond any mortal being? In PHP it's extremely easy,
it's just three lines:
<?
$fileID = @fopen('/path/to/your/file', 'rb');
@fputs($fileID, $contents);  // $contents can be
literally anything, even anobject!
@fclose($fileID);
The thing here is - what is in $contents? I personally don't have a clue how to manually create the contents for a .bmp file for instance - I don't know what should go where in order for a .bmp reader to be able to recognize the file as a "real" bitmap (.bmp) file. I can, however, just put anything I want - anything at all into a file, write it out, calling it a .bmp file. Will it be a .bmp file? No, of course not. So, what is in $contents?
~Bill

Similar Messages

  • How to get DocSet property values in a SharePoint library into a CSV file using Powershell

    Hi,
    How to get DocSet property values in a SharePoint library into a CSV file using Powershell?
    Any help would be greatly appreciated.
    Thank you.
    AA.

    Hi AOK,
    Would you please post your current script and the issue for more effcient support.
    In addition, to manage document set in sharepoint please refer to this script to start:
    ### Load SharePoint SnapIn
    2.if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
    3.{
    4. Add-PSSnapin Microsoft.SharePoint.PowerShell
    5.}
    6.### Load SharePoint Object Model
    7.[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
    8.
    9.### Get web and list
    10.$web = Get-SPWeb http://myweb
    11.$list = $web.Lists["List with Document Sets"]
    12.
    13.### Get Document Set Content Type from list
    14.$cType = $list.ContentTypes["Document Set Content Type Name"]
    15.
    16.### Create Document Set Properties Hashtable
    17.[Hashtable]$docsetProperties = @{"DocumentSetDescription"="A Document Set"}
    18.$docsetProperties = @{"CustomColumn1"="Value 1"}
    19.$docsetProperties = @{"CustomColum2"="Value2"}
    20. ### Add all your Columns for your Document Set
    21.
    22.### Create new Document Set
    23.$newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($list.RootFolder,"Document Set Title",$cType.Id,$docsetProperties)
    24.$web.Dispose()
    http://www.letssharepoint.com/2011/06/document-sets-und-powershell.html
    If there is anything else regarding this issue, please feel free to post back.
    Best Regards,
    Anna Wang
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • How to convert a HTML files into a text file using Java

    Hi guys...!
    I was wondering if there is a way to convert a HTML file into a text file using java programing language. Likewise I would also like to know if there is a way to convert any type of file (excel, power point, and word) into text using java.
    By the way, I really appreciated the help that you guys gave me on my previous topic on how to extract tests from a pdf file.
    Thank you....

    HTML files are already text files. What do you mean you want to convert them?
    I think if you search the web, you can find things for converting those MS Office files to text (or extracting text from them, as I assume you mean).

  • How can I write my Adobe AIR application tracing lines into a log file

    I Have a question about log files for AIR application
    How can I make my application writing all tracing and exceptions into a log file?

    I think if you pubish a -debug SWF it will log to flashlog.txt

  • How to save an existing file into a new file using "save as" method?

    Hai to all,
    if i'm having a file named as "tab.doc"...
    i want to save it as another file as "tab1.doc" by using
    "save as" method....
    Is there any "save as" method available for doing this process....
    thanks in advance..
    senthil..

    Yes.
    See SDKLayoutHelper::SaveDocumentAs in the SDk documentation.

  • How to manage internal 160 GB HD, latest iTunes cannot upload any kind of content to HD

    Hi,
    I have an Apple TV generation 1, with internal 160 GB HD, i used itunes to manage internal content, such as Movies, photos, songs, but recently upgraded iTunes to the latest version ans suddenly, my ATV seems to behave as ATV G3, that means, there is no option to upload any kind of content, since ATV G3 has no HD, it only uses streaming, but now my internal HD is unaccesible, it still has the movies and photos that i uploaded last uploaded, but now the Hard disk seems to be useless!!!!!! SJobs has to think before downgrade functionality on previous versions of HW, please, give me a help!!!!

    Welcome to the Apple Community.
    What type of pairing have you used to link your library. See This.

  • How to write as XML file using java 1.5

    hi all,
    i am trying to create an XML file using java 1.5. I took a XML creating java file which was working with java 1.4 and ported same file into java 1.5 with changes according to the SAX and DOM implmentation in java 1.5 and tried to compile. But while writing as a file it throws error "cannot find the symbol."
    can any body help me out to solve this issue.......
    thankx in advance
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.NamedNodeMap;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.DocumentHandler;
    import org.xml.sax.InputSource;
    import org.xml.sax.helpers.ParserFactory;
    import java.io.*;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();                   
                   dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();                   
    Document xmlDoc =  db.newDocument();
    // this creates the xml document ref
    // parent node reference
    Element rootnd = (Element) xmlDoc.createElement("ALL_TABLES");
    // root node
    xmlDoc.appendChild(rootnd);
    Element rownd = (Element) xmlDoc.createElement("ROW");
    rootnd.appendChild(rownd);
    Element statusnd = (Element) xmlDoc.createElement("FILE_STATUS");
    rownd.appendChild(statusnd);
    statusnd.appendChild(xmlDoc.createTextNode("Y")
    FileOutputStream outpt = new FileOutputStream(outdir + "//forbranch.xml");
    Writer outf = new OutputStreamWriter(outpt, "UTF-8");
    //error is occuring here Since write method is not available in the Document class
    xmlDoc.write(outf);
    outf.flush();

    Hi,
    when I look in the JDK1.4.2 specification I don't see any write method in the Document interface.
    However, your solution is the Transformer class. There you transform your DOM tree into any output you need. Your code sould look something like this:     TransformerFactory tf = TransformerFactory.newInstance();
         // set all necessary features for your transformer -> see OutputKeys
         Transformer t = tf.newTransformer();
         t.transform(new DOMSource(xmlDoc), new StreamResult(file));Then you have your XML file stored in the file system.
    Hope it helps.

  • How to Write in bold to a file using java I/O classes?

    Hi,
    Using I/O classes I want to prepare a .doc file in which some text will be there. I want that text to be formatted. Like some text I want to be bold. Some text to be italic. How can I write bold/Italic text to the file using java I/O classes.
    Thanks
    Prashant

    By .doc file, I'm assuming you mean an MS Word document, yes? (fyi, Word Perfect also used the .doc extension)
    The .doc format is proprietary to Microsoft and isn't documented by them. In order to output a file in .doc format you'd have to understand that format correctly, otherwise MS Word will spit out it's tongue at you, call you names, and maybe send the Microsoft Police to "audit" your PC Software Licensing.
    Fortunately for you there is an open source project to demangle the microsoft file formats. See http://jakarta.apache.org/poi/ and especially pay attention to the HDF project (Horrible Document Format).
    - David

  • How to Write data in Excel File using java

    Hi
    can anybody help me to write data in excel file
    using java code
    Thankx In Advance

    How much are you willing to pay for that?
    If you want it for free, http://jexcelapi.sourceforge.net/

  • How to read pdf files using java.io package classes

    Dear All,
    I have a certain requirement that i should read and write PDF files at runtime. With normal java file IO reading is not working. Can any one suggest me how to proceed probably with sample code block
    Thanks in advance.

    hi I also have the pbm. to read pdf file using JAVA
    can any body help meWhy is it so difficult to read the thread you posted in? They say: java.io is pointless, use iText. So why don't you?
    or also I want to read a binary encoded data into
    ascii,
    can anybody give me a hint how to do it.Depends on what you mean with "binary encoding". ASCII's binary encoding, too, basically.

  • How to create a table in the file using java code.?

    HI,
    I should export the data from the view objects to a word document. I have done that but I should
    display the data in the form of a table.
    Kindly come up with the necessary information on how to create a table in the file using java.
    Thanks,
    Phani

    Hi, Thank you for responding to my query.
    The below are the details of my code.
    DCBindingContainer dcBindings =
    (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding StudentDetailsContent =
    (DCIteratorBinding)dcBindings.get("StudentView1Iterator");
    OutputStreamWriter w = new OutputStreamWriter(outputStream, "UTF-8");
    Row currentRow =
    StudentDetailsContent.getRowSetIterator().first();
    Object a[]= currentRow.getAttributeValues();
    int i;
    for(i=0 ;i<=a.length;i++){
    w.write(a.toString());
    w.write(" ");
    w.flush();
    I am usning this coding to achieve the task of exporting data to file.
    I need to display this information in the table that is where I need help from you people.
    Thanks,

  • How to print a text file using Java

    How can I print a text file using Java without converting the output to an image format. Is there anyway I can send the characters in the text file as it is for a print job? I did get a listing doing this ... but that converted the text to an image format before printing....
    THanks,.

    Hi I had to write a print api from scratch, and I did not convert the output to image. Go and read up on the following code. I know there is a Tutorial on Sun about the differant sections of the snippet.
    private void printReport()
         Frame tempFrame = new Frame(getName());
         PrintJob printerJob = Toolkit.getDefaultToolkit().getPrintJob(tempFrame, "Liesltext", null);
         Graphics g = printerJob.getGraphics();
                    //I wrote the method below for calculations
         printBasics(g);
         g.dispose();
         printerJob.end();
    }This alone wont print it you have to do all the calculations in the printBasics method. And as I said I wrote this from scratch and all I did was research first the tutorial and the white papers
    Ciao

  • How to read the data from Excel file and Store in XML file using java

    Hi All,
    I got a problem with Excel file.
    My problem is how to read the data from Excel file and Store in XML file using java excel api.
    For getting the data from Excel file what are all the steps i need to follow to get the correct result.
    Any body can send me the code (with java code ,Excel sheet) to this mail id : [email protected]
    Thanks & Regards,
    Sreenu,
    [email protected],
    india,

    If you want someone to do your work, please have the courtesy to provide payment.
    http://www.rentacoder.com

  • How can I get my data from a old iPad to a new iPad using iCloud and not iTunes

    How can I get my data from a old iPad to a new iPad using iCloud and not iTunes

    Restore from the iCloud backup - assuming that you were backing up to iCloud in the first place. If you weren't using iCloud for backup - then you are out of luck.
    If you were backing up to iCloud - you have to erase all contents on the iPad in Settings>General>Reset>Erase all content and settings - before you can restore from the iCloud backup.
    Read this article before you do anything else
    http://gigaom.com/apple/ios-101-set-up-and-restore-from-icloud-backup/

  • How do i search for a string in a txt file using java??

    How do i search for a string in a txt file using java??
    could you please help thanks
    J

    Regular expressinos work just fine, especially when
    searching for patterns. But they seem to be impying
    it's a specific group of characters they're looking
    for, and indexOf() is much faster than a regex.If he's reading from a file, the I/O time will likely swamp any performance hit that regex introduces. I think contains() (or indexOf() if he's not on 5.0 yet) is preferable to regex just because it's simpler. (And in the case of contains(), the name makes for a very clear, direct mapping between your intent and the code that realizes it.)

Maybe you are looking for

  • HELP!  Stuck in a Loop after Erase & Install Tiger 10.4

    Here's what happened: My old G4 PPC PowerMac suddenly started running everything (including on startup) very slowly. A weird sound was coming from the HD? (not sure) but it sounded like it was constantly doing something. The sound was a regular: chik

  • Why can't my mid-2011 macbook air detect thunderbolt 1.2.1 update

    I'm using a 13 inches mid-2011 macbook air with OS X 10.7.4 on 12 June, I found the update of Thunderbolt 1.2 in the system update center and I patched it. Luckliy, this patch didn't kill my kernel as it did to many other machines. But I'm still a bi

  • Taking long time to initialize planning area.

    Hi All, Few questions on initalizing planning are. We have about 500000 CVC and 8 millions records in it.  We have recently upgradd to SCM 7.0. I am noticing now that every time we run background job to create CVC and initialize planning are, I notic

  • Creating a new MdmMetadataProvider

    Hi, I created a MdmMetadataProvider using the following code Class.forName("oracle.jdbc.driver.OracleDriver");           String url="jdbc:oracle:oci8:@(description="+ "(address=(host=hostname)(protocol=tcp)"+ "(port=1521))(connect_data=(sid=sidname))

  • TS1347 After one week, my i phone 5s has lost my calendar.  I need to retrieve it

    Help? I just upgraded from i phone 4 and all my old phone was transferred to the new one by Verizon store guy.  The calendar was working just fine yesterday, but I tried to add two items today and could not get them entered, plus I lost what was alre