Files to bytes

i want to store the word document into the data base. how can it be done by converting the word document to bytes and then store the same in the data base.

Hi,
Check threads like
https://forums.sdn.sap.com/click.jspa?searchID=674048&messageID=2775568
https://forums.sdn.sap.com/click.jspa?searchID=674064&messageID=2843579
Eddy

Similar Messages

  • DPT-S1 Feature Add Request: File Size (bytes) Sorting and Display in Documents Lists

    Document Lists view should include option to sort by and display file Size (bytes), as in all other file tools.
    That would permit discovery of duplicate files with different names, and trimming out the largest files to save space.
    Thanks!

    Anyone reading this? Agreeing with me?

  • Converting Files to bytes

    hello
    Just want to know if there anyway to convert a text file to bytes. I can read the textfile but i want to convert them to bytes and store them.

    http://java.sun.com/j2se/1.4.1/docs/api/java/io/InputStream.html
    http://java.sun.com/j2se/1.4.1/docs/api/java/io/OutputStream.html
    Note that the Input[Output]Streams conserve extra byte information other than the content of a text.

  • How to write newline character to file using bytes along with content

    Hi All,
    I need to write headers into the file using byte[]. I am creating the strings of header which will form the different rows in the file. I am new to java and would like to know how to embed new line character so that when the byte[] is written to file headers come in different rows.
    like
    hrd1:abcd
    hdr2:1234
    when i embed \n and \r in string and do getBytes() and write it to file, some boxes are written in the file and everything comes into single line.
    Please advice me the correct way .
    Thanks in advance.
    Cheers!!
    Puneet

    not sure about it, but i was always told that "\r\n" meant "new line" on "lots of documents" whereas "\n" only or "\r" only were meaningless on some type of documents

  • How do I read directly from file into byte array

    I am reading an image from a file into a BuffertedImage then writing it out again into an array of bytes which I store and use later on in the program. Currently Im doing this in two stages is there a way to do it it one go to speed things up.
    try
                //Read File Contents into a Buffered Image
                /** BUG 4705399: There was a problem with some jpegs taking ages to load turns out to be
                 * (at least partially) a problem with non-standard colour models, which is why we set the
                 * destination colour model. The side effect should be standard colour model in subsequent reading.
                BufferedImage bi = null;
                ImageReader ir = null;
                ImageInputStream stream =  ImageIO.createImageInputStream(new File(path));
                final Iterator i = ImageIO.getImageReaders(stream);
                if (i.hasNext())
                    ir = (ImageReader) i.next();
                    ir.setInput(stream);
                    ImageReadParam param = ir.getDefaultReadParam();
                    ImageTypeSpecifier typeToUse = null;
                    for (Iterator i2 = ir.getImageTypes(0); i2.hasNext();)
                        ImageTypeSpecifier type = (ImageTypeSpecifier) i2.next();
                        if (type.getColorModel().getColorSpace().isCS_sRGB())
                            typeToUse = type;
                    if (typeToUse != null)
                        param.setDestinationType(typeToUse);
                    bi = ir.read(0, param);
                    //ir.dispose(); seem to reference this in write
                    //stream.close();
                //Write Buffered Image to Byte ArrayOutput Stream
                if (bi != null)
                    //Convert to byte array
                    final ByteArrayOutputStream output = new ByteArrayOutputStream();
                    //Try and find corresponding writer for reader but if not possible
                    //we use JPG (which is always installed) instead.
                    final ImageWriter iw = ImageIO.getImageWriter(ir);
                    if (iw != null)
                        if (ImageIO.write(bi, ir.getFormatName(), new DataOutputStream(output)) == false)
                            MainWindow.logger.warning("Unable to Write Image");
                    else
                        if (ImageIO.write(bi, "JPG", new DataOutputStream(output)) == false)
                            MainWindow.logger.warning("Warning Unable to Write Image as JPEG");
                    //Add to image list
                    final byte[] imageData = output.toByteArray();
                    Images.addImage(imageData);
                  

    If you don't need to manipulate the image in any way I would suggest you just read the image file directly into a byte array (without ImageReader) and then create the BufferedImage from that byte array.

  • How to store a mid file in byte[ ]

    I used this method to store the song but it does not seem to be working.
    public byte[] getSongAs_ByteArray() {
        byte[] data = new byte[50848];
        InputStream in = null;
        try {
          HttpConnection connection = null;
          Connector.open("http://www.ziyaaf.com/XML/girl.mid ");
          connection = (HttpConnection) Connector.open(
              " http://www.ziyaaf.com/XML/girl.mid");
              in = connection.openInputStream();
               DataInputStream dis = new DataInputStream(in);
          dis.readFully(data);
          in.close();
        catch (IOException ex) {
          System.out.println("::" + ex);
        return data;
    But if i use this method it works
    public byte[] loadSong() {
        byte[] data = new byte[50848];
        try {
          Class c = this.getClass();
          InputStream is = c.getResourceAsStream(" girl.mid");
          DataInputStream dis = new DataInputStream(is);
          dis.readFully(data);
          is.close();
        catch (IOException ioe) {
          ioe.printStackTrace();
        return data;
    But i want to load the song from a remote location
    And this is the method i used to play the mid file.
    ByteArrayInputStream b = new ByteArrayInputStream(getSongAs_ByteArray());
        try {
          player = Manager.createPlayer(b,
                                        "audio/midi");
          player.start();
        }

    onnector.open("http://www.ziyaaf.com/XML/girl.mid
    connection = (HttpConnection) Connector.open(
    " http://www.ziyaaf.com/XML/girl.mid");
    Firstly, you call open twice, you don't check for http errors, and on the first URL you have a space after the ".mid", and on the second URL your have a space before "http".
    And never ever use fixed size byte arrays!
    And why load the midi file in memory when you can play it directly from stream (specially if you read from file)?

  • Output says "The number of bytes in the file are 0" but the file has bytes

    Dear Java People,
    Why would an output say a file has 0 bytes when upon doing a search for the file in Windows Explorer it say the file has 1 -4 kbytes ?
    for example part of my output was :
    "the number of bytes in TryFile3.java are 0"
    caused by the following lines of code:
    System.out.println("\n" + contents[i] + " is a " +
    (contents.isDirectory() ? "directory" : "file\n") +
    " last modified on " + new Date(contents[i].lastModified())
    + "\nthe number of bytes in TryFile.java are " + myFile.length());
    thank you in advance
    below are the two program classes
    Norman
    import java.io.File;
    import java.io.FilenameFilter;
    import java.util.Date;
    public class TryFile3
       public static void main(String[] args)
           //create an object that is a directory
             File myDir =
            new File("C:\\Documents and Settings\\Gateway User\\jbproject\\stan_ch9p369");
              File myFile = new File(myDir, "TryFile3.java");
            System.out.println("\n" + myDir + (myDir.isDirectory() ? " is" : " is not")
            + " a directory.");
             System.out.println( myDir.getAbsolutePath() +
             (myDir.isDirectory() ? " is" : " is not") + " a directory.");
              System.out.println("The parent of " + myDir.getName() + " is " +
              myDir.getParent());
               //Define a filter for java source files Beginning with the letter 'F'
               FilenameFilter select = new FileListFilter("F", "java");
               //get the contents of the directory
               File[] contents = myDir.listFiles(select);
                //list the contents of the directory
             if(contents != null)
                 System.out.println("\nThe " + contents.length  +
                 " matching item(s) in the directory " + myDir.getName() + " are:\n " );
                 for(int i = 0; i < contents.length; i++)
                   System.out.println("\n" +  contents[i] + " is a " +
                   (contents.isDirectory() ? "directory" : "file\n") +
    " last modified on " + new Date(contents[i].lastModified())
    + "\nthe number of bytes in TryFile3.java are " + myFile.length());
    else {
    System.out.println(myDir.getName() + " is not a directory");
    System.exit(0);
    import java.io.File;
    import java.io.FilenameFilter;
    import java.util.Date;
    public class FileListFilter implements FilenameFilter
    private String name; // file name filter
    private String extension; // File extension filter
    public FileListFilter(String name, String extension)
    this.name = name;
    this.extension = extension;
    // static boolean firstTime = true;
    public boolean accept(File diretory, String filename)
    //the following line of code can be inserted in order to find out who called the method
    // if(firstTime)
    // new Throwable("starting the accept() method").printStackTrace();
    boolean fileOK = true;
    //if there is a name filter specified, check the file name
    if(name != null)
    fileOK &= filename.startsWith(name);
    //if there is an extension filter, check the file extension
    if(extension != null)
    fileOK &= filename.endsWith('.' + extension);
    return fileOK;

    System.out.println("\n" + contents + " is a " +
    (contents.isDirectory() ? "directory" : "file\n") +
    " last modified on " + new Date(contents.lastModified())
    + "\nthe number of bytes in TryFile.java are " + myFile.length());I haven't read any of your italicized code, but perhaps there is a good reason why you have "myFile.length()" and not "contents.length()" in this line of code?

  • Reading file in bytes using FileReader...

    Hi,
    I am trying to read out bytes value from a .bmp file then i try to change the byte values that i read out to hexadecimal value.
    I open the .bmp in Win Hex (a software) but the hexadecimal value does not tally....
    public void readByteFile (String path)
    Vector in = new Vector ();
    try
    FileReader reader = new FileReader (path);
    int c;
    while ((c = reader.read ()) != -1)
    String hex = Integer.toHexString (c);
    reader.close ();
    } catch (FileNotFoundException e) {System.err.println(e);}
    catch (IOException e) {System.err.println(e);}
              return in;
         }

    If you want to read the actual bytes from the file then do not use a Reader. That will convert the bytes to characters as if they were text. Use an InputStream instead.

  • Binary file read byte unmatch

    I tried to read one line of binary file as the top of the screenshot.
    The result is as the left side. It shows the first part with text are correct. The ending part is not match with the raw one.
    I also tried read by byte, but still the same.
    Any suggestion, thanks.
    Solved!
    Go to Solution.
    Attachments:
    shot.JPG ‏48 KB

    What program created this binary file?
    If you can figure out how the file was created, then you can figure out how to read it.
    We can't help because all you've shown are some bytes and say that some are right and some are wrong.  What is the "raw one" you are referring to?  What do you expect it to look like?
    Message Edited by Ravens Fan on 01-26-2010 11:15 PM

  • If reading file as bytes (DataInputStream), how find delimiter?

    I have to read a file in as a DataInputStream because it is really two files (one text, one can be a .doc, .jpg, etc) mixed into one. The files are separated by a delimiter which is something like: "--34f5s--a23--34d--". The binary file data is also ended by that delimiter as well. So how would I find the delimiters while not converting the byte stream and losing data?

    You're probably not going to like this suggestion...
    The only way I can think of off the top of my head is to get the byte array representation of the delimiter, and as each byte passes through your InputStream, compare it with the delimiter array, finite-state-machine-style.
    Send the data on if it doesn't match, otherwise keep matching against the delimiter. If you match halfway and the mismatch, send on the bytes that matched as well as the last byte which didn't. If you match to the end of the delimiter, then the first file is (should be) exactly what you sent on.
    Alternatively, assuming this is for a MIME-style attachment, is there anything in javax.mail that would do this for you? Or another third-party library?

  • How to create PNG file from byte array of RGB value?

    Hi
    Here is my problem.
    I have drawn some sketchs (through code in runtime) on canvas. I have grabbed the RGB information for the drwan image and converted to byte array.
    I have to pass this byte array to server and generate a png file and save.
    Please help.

    {color:#ff0000}Cross posted{color}
    http://forum.java.sun.com/thread.jspa?threadID=5218093
    {color:#000080}Cross posting is rude.
    db{color}

  • Reading file containing byte data

    I am trying to read a file containing data that is in byte format. I can't look at the file and have no idea what is in there. For my first pass I would just like to see what the format is of the data in characters. Is there an easy way to do this? This is what I have done so far:
    //file is read from another method and is passed in here.
    try {
    BufferedReader f = new BufferedReader(new FileReader(file));
    String t;
    while ((t = f.readLine()) != null) {
    byte b[] = t.getBytes();
    System.out.println("bytes " + b[0]);
    System.out.println("chars " + (char)b[0]);
    catch(Exception e) {
    e.printStackTrace();
    The output is looking like this:
    bytes 72
    chars H
    bytes 74
    chars J
    bytes 81
    chars Q
    bytes -56
    chars ?
    Which one is the character value of the bytes? I am assuming the char one, but it sure seems like funny values. Also, I want to read the whole line and then get the whole line converted, not just the first byte. Isn't getBytes just getting the first byte? How can I convert the whole line after it is read (f.readLine())?
    Thanks.
    Allyson

    Well, I tried that and it still gives me just the binary or byte data (I have no idea what kind it is - I know I can't read it when I try to open it with notepad). There is a current application that uses this file and opens it and provides the data when it is opened. I am trying to look thru that code to find out what it does, but it is very confusing. It is written in c.
    Any other ideas out there as to how to open and display the correct data in a file like this? When I did the binary data open this is the kind of data I got:
    char in new loop Q
    char in new loop
    char in new loop @
    char in new loop
    char in new loop @
    char in new loop @
    char in new loop
    char in new loop
    char in new loop @
    char in new loop L
    char in new loop `
    char in new loop :
    char in new loop @
    I know that data is mostly numbers and maybe a few names, but nothing like that.
    Thanks.
    Allyson

  • Compilationerror to files 64 byte

    Hello,
    i have a problem to compile files greater than 64 byte. i get the error-message: code too large for try statement.
    i use the jdk version 1.4.2_005.
    in the bugdatabase i read, that this problem is 'working' in jdk's < 1.4.2.
    what is wrong? what's my mistake?
    best regards
    uwe

    thank's for your answer. that's not possible.
    i use a tag-library with sql-statements and
    generate jsp-files to output. i have no influence on
    the classes in the tag-library.
    It has to be possible because 64K is an absolute limit. You should remove all your data access and business logic out the JSP so that your JSP has only the display logic.

  • Getting Finder to add file's bytes together.

    I have an mp3 player which is limited to two GB. Is there any way I can highlight files [music files] in Finder and get them to add the bytes together instead of having to add them individually?

    I'm not sure what you are asking. do you want to find out the total size of several selected items? then select them in finder and enter commandoptioni.

  • How to write a header with an array of u16 to a file with byte stream

    Hello,
    I have a header file and an array of u16.
    The header file's size is fixed with 2048 bytes.
    I need to add the header file at the beginnig of the array of u16. I'm trying to use 'header','pos mode' and 'pos off'terminals in the 'write file.vi', but I don't know how to use them.
    Please give me help
    Thank you in advance

    My example was in LV 6.1 version.
    I attach here the 2 vis in LV 6 version.
    Let me know if it works,
    Alberto
    Attachments:
    write.vi ‏32 KB
    read.vi ‏37 KB

  • How can i upload empty files (0 bytes) in mac, ff 3.6.13?

    im developing an application that has an upload input file. I tested it with ff 4 in ubuntu, and it woks ok, but on mac with ff 3.6.13 I cannot upload 0 Bytes files.

    Are you uploading to the same server, or are these different instances of your server one each on mac and linux? (I presume you are using Apache as your server?)
    If these are merely local server instances and not the same physical separate server, then my guess would be a config issue that is different between the two.
    Also, is this straight from scratch or are you developing this with something like SWFupload or via Drupal? There are known problems with those two with zero byte files in some cases.
    Finally, are you using cgi, php, ruby etc? Which one are you using to handle the upload code?

Maybe you are looking for