Binary file to variable

Hi,
I want to store a binary file content (it is a MS WORD file) onto a java variable (type String ?) to use this variable to create a new file identical by writing this variable value into a new file.
I tried it as follow :
1- I read a file using a fileInputString and method read
2- I got a byte array, converted it in a String and using URLEncoder produced another String
3- With this encoded String I created a java code that I displayed on System.out, It looks like :
String content=""
+"%D0%CF%11%E0%A1%B1%1A%E1%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%3E%00%03%00%FE%FF%09%00%06%00%00%00%00%00%00%00%00%00%00%00%01%00%00%00%21%00"
+"%00%00%00%00%00%00%00%10%00%00%23%00%00%00%01%00%00%00%FE%FF%FF%FF%00%00%00%00+%00%00%00%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%F"
+"%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00";Now I have my binary file in a string and using URLDecoder and writing this String into a new file I must obtain a clone of the original file, but when I compare the original file with this file with command cmp I always obtain severals differences (about 10 or 12 bytes that are differents in a total of 180000) I don't know why theses two files are differents, is there a way to obtain a perfect clone ?

Hi,
I want to store a binary file content (it is a MS
WORD file) onto a java variable (type String ?) to
use this variable to create a new file identical by
writing this variable value into a new file.If you want to copy a file, never ever use Strings, use bytes!
Have a look at the IO tutorial how to read a file as a byte stream:
http://java.sun.com/docs/books/tutorial/essential/io/

Similar Messages

  • Reading a binary file to string variable does not populate correctly

    Hi, I am new to Adobe Air/Flex and I'm trying to read a
    binary file which also contains text in "cleartext". The problem
    I'm having is that when I call FileStream.readUTFBytes method, only
    the first 6 characters are showing up in my string variable
    "contents" when I debug it in FlexBuilder or use a trace command
    and debug it. I have also tried with other types of files but I
    have a similar problem unless it's a non-binary file.
    Am I doing something incorrectly or should I be reading a
    binary file differently than the way I'm reading it currently?
    The source code is shown below.
    TIA,
    Magnus
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:Script>
    <![CDATA[
    import flash.filesystem.File;
    private function readFiles():void{
    var feedFile:File = File.userDirectory.resolvePath( "Local
    Settings/Application Data/Microsoft/Feeds/AppScout~.feed-ms" );
    var stream:FileStream = new FileStream();
    stream.open( feedFile, FileMode.READ );
    var contents:String =
    stream.readUTFBytes(stream.bytesAvailable);
    trace(contents);
    stream.close();
    ]]>
    </mx:Script>
    <mx:Button x="121" y="66" label="Button"
    click="readFiles()" />
    </mx:WindowedApplication>

    It's difficult to tell what it is, it looks like a binary
    pipe symbol but I can copy it from TextPad for example. Some of the
    characters following it cannot be copied from TextPad which I
    assume is because it's null. I can read the whole file in C#/.Net
    and assign it to a string variable without any problems but perhaps
    Air is somewhat limited to binary content.

  • Read Binary File - variable binary format

    Hi Everyone,
    I'm using the "read from binary file" subvi to interpret some data from a file. I have the code running fine if the the temp file is always the same format, however I want the "read from binary file" to adapt to different file structures based on a user input. Here's a snapshot of my current VI:
    The structure of the file I'm reading can change, so I tried to make it so that user input would change the way labview interprets the binary structure. I did this using case structures. The issue I ran into is that the ouput of the different case structures merges into 1 line, and since each case structure's binary format is a different array size I get an error:
    ======>
    Does anyone know of a way to remedy this issue?
    If you take a look at my file, I was thinking about putting all of my commands that interpret the binary file and parse the data into a case structure similiar to the one above. I was trying to avoid this as I would end up with a set of the entire code in 12 different cases, and if I wanted to make a small change to the the code I would have to change all 12 cases.
    Thanks for any suggestions!
    Attachments:
    Read Copy of Binary File - Static.vi ‏105 KB
    Read Copy of Binary File - Variable.vi ‏105 KB

    One solution is to include the File Read into the case structure. But you need to find a way to return the different types of data records as you obviously can't connect them to the same indicator.
    All in all I find your design rather crude anyhow. Reading a file and letting the user decide what data type to expect is going to give lots of errors. Instead the file should contain information of what is in there and the reading routine should decide based on that how to interpret the next bunch of data.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How to output variable names and units used in binary file

    My colleague will be giving me binary files (*.dat) generated from within LabView. There are over 60 variables (columns) in the binary output file. I need to know the variable names and units, which I believe he already has set up in LabView. Is there a way for him to output a file containing the variable name and unit, so that I'll know what the binary file contains? He can create an equivalent ASCII file with a header listing the variable name, but it doesn't list the units of each variable.
    As you can tell I am not a LabView user so I apologize if this question makes no sense.
    Solved!
    Go to Solution.

    Hi KE,
    an ASCII file (probably csv formatted) is just text - and contains all data that is (intentially) written to. There is no special function to include units or whatever!
    Your collegue has to save those information the same way he saves the names and the values...
    (When writing text files he could use WriteTextFile, FormatIntoFile, WriteToSpreadsheetFile, even WriteBinaryFile could be used...)
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • To read structure variable from a binary file

    Hi Everyone,
    Iam having a binary file created by c++.It contains structure  like this one...
    struct
          char name[2];
          unsigned short num;
          char identity[4];
          double date;
          union
              byte id[4];
              int sizeconst;
              int size;
    I want to read this struct file in labview. How can i do that?

    Once I had the same problem, I've asked NI-support and they said to me because of different kind of reading method that that operation is impossibile to do, so the solution to solve the problem has been to create a C++ library that reads the structure from the file and makes disponible the data. After, I've called the library by "Call by library function" in my Labview software.
    Ricky
    Italian Developer engineer
    www.www.selt-sistemi.com

  • Deleting a single element from a binary file

    I am working on a server application that must keep track of the messages that have been sent but not responded to.  After I send a message, I append it to an array cycling through an uninitialized shift register and I write it to the end of a binary file.  When I receive a response to a message, which was probably but not necessarily the first message sent, I delete that message from the array and the file.  This allows me to look up entries quickly but also to maintain a permanent record of what messages have been sent and not responded to.
    Basically, I need an intelligent way to make a file, or any other permanent storage medium, act effectively like a queue.  The problem with the current implementation is that when I delete one variable-sized entry from the file, I need to move all subsequent entries, which are usually all of the other entries in the file, forward in memory to take its place.  Is there a way to get around recopying the majority of the file or to implement this entire thing more intelligently?

    You can organize your datafile as a list. For example In this list any record consists of a fixed size data field and referencies (file position f.e.) to the next record and  to the previous record. You can then rewrite the record-have-to-be-deleted with new one, or you can "delete" this record modifiyng the referencies of the "previous" and the "next" records. When you will add a new record you can write one at this "free" place.
    The other way is to manage two files. The first one contains your data record by record. The second one contains the numbers of the records and the corresponding datafile positions or record counter. This second file can be very small and easy-to-manage. It can represent the only record's queue position in the datafile. You can rewrite your records, mark them as deleted without moving large portions of data.
    You can setup the datafile capacity in "number of records" term.
    Additionally it is possible to use the records with variable length but it will be much more dificult. 
    Best regards, Evgeny. 

  • How can I read a binary file stream with many data type, as with AcqKnowled​ge physio binary data file?

    I would like to read in and write physiological data which was saved by Biopac�s AcqKnowledge 3.8.1 software, in conjunction with their MP150 acquisition system. To start with, I�d like to write a converter from different physiodata file format into the AcqKnowledge binary file format for version 3.5 � 3.7 (including 3.7.3). It will allow us to read different file format into an analysis package which can only read in file written by AcqKnowledge version 3.5 � 3.7 (including 3.7.3).
    I attempted to write a reader following the Application Note AS156 entitled �AcqKnowledge File Format for PC with Windows� (see http://biopac.com/AppNotes/app156FileFormat/FileFo​rmat.h
    tm ). Note the link for the Mac File format is very instructive too - it is presented in a different style and might make sense to some people with C library like look (http://biopac.com/AppNotes/app155macffmt/macff.ht​m) .
    I guess the problem I had was that I could not manage to read all the different byte data stream with File.vi. This is easy in C but I did not get very far in LabView 7.0. Also, because it is for PC I am assuming the data to be written as �little endian� integer, and thus I also used byte swap vi.
    I would be grateful if you someone could explain how to handle such binary file stream with LabView and send an example to illustrate it.
    Many thanks in advance for your help.
    Donat-Pierre

    One more step...
    short are U16 integer
    double are double precision float
    bool seem to be 2 bytes (= U16)
    char are string (variable length)
    rgb are U16 integer, with high order byte = 0
    rect should be 4 x U16 (top, left, bottom, right)
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • Writing binary files & trouble with no unsigned byte type

    I've got a fair amount of Java experience, enough to know what I'm doing most of the time but I do have a vast experience with C & C++ which helps my Java. I've stumbled across a problem when trying to write out files in binary.
    If I was to write out a binary file, I would always choose C/C++ to do this because simply because I'm at ease with the implementation.
    I've now written a Java program which needs to output a file in binary and I'm having real issues doing the most simple things because of no unsigned support.
    I want to write out elements byte-by-byte and make use of the 8-bits provided in the byte type in Java.
    Let's assume I've done my processing and I end up with an int. I know that this int is 0-255 in value. I now want to pack it into a byte and write it to my file. How do I go about assigning the byte without Java 'converting' it to a signed byte? I simply want to copy the lower 8-bits of the int and duplicate them into the byte variable - no conversion.
    In C you would do something like this:
    char mySignedChar = *( (char*)&(unsigned char)myInt ) );
    What's the Java equivalent? Am I going about this the right way?

    Whether a byte is signed or unsigned only matters if one is doing arithmetic on it. If the int is 0-255 then you just cast to a byte using
    byte theByte = (byte)theIntValue;When reading back you just use
    int theByteAsAnInt = theByte & 0xff;

  • Problems with binary files

    Hello everybody!
    I'm having deep trouble with reading from binary files.
    I have opened a DataInputStream with a FileInputStream to read the data (which consists of a lot of short-Variables) into my program.
    Then I wondered why the data read is always wrong, until I discovered the core of the problem yesterday night. It seems as if Java reads everything correct, but the 16bit unsigned int data from the file has a problem.
    It seems as if the second byte is written first, that means i.e. the decimal 2352 (Hex: 09 30) is written 30 09, and that wreaks havoc upon my program, because Java interprets this as dec 12297.
    Now I have the following questions:
    1. Is this a kind of one- or two-complement problem?
    2. Is it possible to read this in a byte array (yes), and convert this byte array afterwards into a short variable?
    3. Is it possible to read this kind of data with a Java class?
    Thank you very much in advance,
    Hans Munzel

    Thank you for your quick reply!
    I already thought that this is the right way to solve this. Now I have already looked it up:
    - I have found no class that is able to transform a byte array into a basic data type.
    - The class Integer is able to convert int variables into a Hex string, making it possible to concatenate the Strings in the correct order and convert it.
    - The class Byte is unfortunately NOT able to do this.
    So, I have tried to make a conversion via combinations of toString(), decode(), and parseInt() (and a lot of other methods, too), but this is a) very complicated and b) prone to errors which result normally in a fatal exception.
    So, am I missing something? I am using JDK 1.3.1, and have looked through the java.lang and java.math packages, but I found nothing I can use.
    The only thing close to converting a couple of bytes to a Java datatype is the DataInputStream with its readShort() etc. methods, but is is causing the problem in the first place ...

  • Huge binary file size difference LV 6.1 to LV 8.2

    I have an application that was first developed under LabVIEW 4.2 and has been periodically upgraded as necessary.  It is normally run as a built application so LabVIEW version changes only come in when something in the application has to be changed.  That occasion occurred and we changed from LabVIEW 6.1 to LabVIEW 8.2 for the build environment.  No changes were made to any of the file handling vis (other than what LabVIEW did in the conversion, which I didn't check at all).
    The problem is that this application writes a large structure (4320 elements in each of 13 single-precision variables) into a binary file once a day.  When I started the new version of the application the size of the files went from 242956 bytes to 775334 bytes.
    The vi to read these files still works for the old files as well as the new files and a set of C routines that I use to read the files seems to also work correctly with the new files - at least the data looks like it is supposed to when it is plotted.
    The change in file size is a concern since this application is supposed to keep writing these files every day for many years into the future.
    Is there any known way to return to the original behavior with the smaller files?

    Hi Bryan,
    you say: "all changes are made with rotates and insert elements to prefent the arrays from growing"!
    You should use "replace array elements" to prevent array growth!!! Please check this with your application!
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • How can I read a binary file?

    In my AIR application, I'm trying to read a binary file and then post it via an HTTPService to a remote ColdFusion component that accepts a "binary" type argument.  The result of the post is always:
    The FILEOBJ argument passed to the addFile function is not of type binary.
    Here is how I'm reading the file in Flex, where fileObj is of type File:
    var fs : FileStream = new FileStream();
    var bytes : ByteArray = new ByteArray();
    fs.open(fileObj, FileMode.READ);
    fs.readBytes(bytes, 0, fs.bytesAvailable);
    fs.close();
    I then pass "bytes" as the parameter to my HTTPService's send call, like so:
    var params : Object = {method : "addFile", fileObject : bytes};
    service.send(params);
    When I debug, bytes contains the correct file size.  Is it not in binary form?  I've tried several other suggestions, but with the same result, so would appreciate any help.
    Thanks!

    One more step...
    short are U16 integer
    double are double precision float
    bool seem to be 2 bytes (= U16)
    char are string (variable length)
    rgb are U16 integer, with high order byte = 0
    rect should be 4 x U16 (top, left, bottom, right)
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • Saving ResultList as binary file

    Hi,
    I like to store my ResultList as binary on file drive. The aim is to safe drive space and execution time for creating the report (XML or ASCII) for each UUT.
    At the moment i had nothing figured out doing such stuff in TS.
    Thats the reason why I started this thread to discuss with you what is possible or impossible.
    Do not care about the programming language. LV,CVI,C++,C# or anything else is welcome.
    My idea sounds simple
    1.) Creating : Take the address space of the ResultList and save it to disk. Problem: Size of Buffer !!
    2.) Consuming: Take the Binary file and put it back to TS and let a the TestReport (XML, ASCII or whatever you want) Callback running.
    Greetings from the lake of Constance, Germany
    Juergen
    =s=i=g=n=a=t=u=r=e= Click on the Star and see what happens :-) =s=i=g=n=a=t=u=r=e=

    Hi Johann,
    Thanks for your answer. But unfortunately it pointed not out what I really want to know. Or lets say what i want to discuss.
    The major task is: Is there a way to safe a the complete ResultList (if you take a look into the TestReport-Callback it will be variable "Parameters.MainSequenceResults") as a binary-file without any modifiactions or generator/parser stuff.
    The first aim of this procedure should be no loss of data by saving huge number of file drive space. The Second is saving execution time for generating the report file in the Testreport callback.
    The last few "lunch-breaks" I have dealed with this question to figure out a useful solution.
    I have found several things in TS4.0 that deal with this topic the serialization of data
    One the one hand there is a Engine method "SerializeObjects" . I got this running (I hoped so) for binary data but for re-building
    just for visualizing the data to an Operator. I found no running solution. On the other hand there is PropertyObject method
    "Serialize" This stuff was working fine. But data always have been stored in INI-Format on file. So there was no great benefit
    on file size.
    While looking on the TS4.0 poster on the wall i was focused on PropertyObjectFile. And with it found a resonable solution for this task. It is simple. Create a  PropertyObjectFile, do some settings like binary and path, get the parent PropertyObject from it, and ceate a new varaiable in the data folder. Now take the ResultList, clone and add it to your variable. The last step is saving.
    A comparsion to the XML-Report (shipped with NI)
    Binary  <-->  XML
    Filesize: 23 kB  <--> 2202 kB  that is a reduction of filedrive space of over 95% !!!
    Executiontime 160ms <--> 1960ms  that means i have to spent only 8% of time as in XML
    I have attached an example. It writes the report on Root C:\report.dat
    For you and all other members feel free to test it and please tell me what you think about it.
    If there is an other solution so lets discuss it.
    Greetings 
    juergen
    =s=i=g=n=a=t=u=r=e= Click on the Star and see what happens :-) =s=i=g=n=a=t=u=r=e=
    Attachments:
    ResultListAsBinary.seq ‏12 KB

  • Streaming data from cRIO to a data file (binary file) on a network Network Drive on the same LAN

    Dear All 
    I hope my message finds you all well 
    My Question is :  is it possible to log my data from cRIO to a network drive and stream the data being captured to a binary file in this drive ? and do the conventional File IO functions ?
    I heard that DataSocket can do this , but it is mainly used between computers (this is what i understood so far about it)
    My network drive is a DLink ShareCenter : http://sharecenter.dlink.com/products/DNS-320
    I know that i can use the NI 9802 SD Card module , but it is out of my budget now to buy it 
    Please assist 
    Best Regards
    Eng. Mohammed Ashraf
    Certified LabVIEW Associated Developer
    InnoVision Systems Founder, RF Test Development Engineer
    www.ivsystems-eg.com

    Hi Mohammed,
    Are you trying to accomplish all this with or without the use of a host machine? If you're doing it with a host machine then the best bet would be to transfer data to the host using network published shared variables and then write to a file on the network from there. 
    If you're trying to do all this from the cRIO straight to the network drive with no intermediate host PC there are many things to consider. First off would be making sure there are no security protocols on the network drive that would prevent the cRIO from accessing it. Next you'd have to make sure there are no drivers required for the network drive as many drivers will not work on the Real-Time OS since most of these drivers are designed for a Windows system. If all this is taken care of then I'd say FTP is probably your best bet for getting files onto the network drive as long as you have an FTP server. 
    I'm unsure about if you would be able to stream to a binary file from a cRIO. I would need to know more about your application and what hardware you're using. Again I'd recommend you use a host PC and do the file I/O from there if possible. Can you tell us a bit more about your application and setup?
    Miles G.
    National Instruments
    Applications Engineer

  • Binary File to Array

    I need to choose a file with a file chooser and then convert it to an array.  The file is a binary file and I just want every byte out of it as an element in a very large byte array.  Im not quite sure how to go about this, can someone who has done this or knows how guide me in the right direction?
    When I run the enclosed vi it acts as if the file is not 512 bytes big and says that an EOF has been reached.  Im sure Im just doing it plain wrong tho .
    The zip contains two of the files I wish to read in as well as my poor attempt to read the file into a byte array. The vi has two main problems:
    1) It doesn't work
    2) It doesn't take into account variably sized files
    Thanks
    Cason Clagg
    SwRI
    LabView 7.1, Windows XP
    Attachments:
    FileOpen.zip ‏12 KB

    (1) You wire a byte stream type of I32, meaning you read 4x as many bytes as intended.
    --> solution: right click in the type constant and select Representation:U8.
    (2) You can get the actual file size e.g. with the eof function.
    See attached modification (LabVIEW7.1).
    ... and don't forget to close the file when done
    Message Edited by altenbach on 07-21-2005 06:16 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    OpenFileMOD.vi ‏24 KB

  • Binary file data plugin : navigating through different data types

    Hi
    I am currently trying to load a binary file into DIAdem with the following structure:
    block 1
    1x 8-bit ascii
    12x double
    block 2
    1280x int16
    block 3
    1280x int16
    block 4
    12x double
    block 5
    1280x int16
    block 6
    1280x int16
    block 7
    12x double
    block 8
    1280x int16
    block 9
    1280x int16
    I managed to read the first string value, but I was unsuccessful in getting any further.
    Could anyone please give me a lead on how to proceed?
    /Phex

    Sorry for revoking this thread, but I need some further advice on two issues:
    1. All values that are set to -32768 in the data mean actually NaN. Right now I am converting all those values to NaN in a post-processing script using the CTNV function. Is there a way to do this directly in the DataPlugin? My idea was to apply the NoValueSet command but the bInterfaceLocked variable returned TRUE, so not accessible. No problem if there is no other way, I can live with the CTNV function.
    2. When I tested the DataPlugin with larger files (up to 1 GB) I pretty quickly ran into the maximum channel number limitation of DIAdem (available 65k, needed 400k). The only thing I could think of right now is to concatenate all data to a few channels and then extract the relevant blocks needed for the analysis during post processing. But that does not seem very efficient and will surely bring up other problems. Is there a way to work with the DataPlugin interactively, i.e. tell the plugin to read X number of blocks at file position Y? Or is it possible to save loaded data sequentially to different files within the plugin? Increase the number of available channels? Any comments or other ideas are very much welcome.
    /Phex 

Maybe you are looking for

  • Can't send Mail after Mac OS 10.4.3 Update

    Darn, I wish I hadn't run the latest update on a number of Mac G4s. I had no issues whatsoever with Mac Mail 2.0 using IMAP on our Exchange server until the latest update. Currently users are having sporadic issues with mail getting stuck in the outb

  • Organisational  structure replication

    Hi, We have 2 structures HR and SRM structure.We are making HR structure as main structure and want to replicate to SRM. Both structures are different HR structure has the FI table where the approvers are sitting for bujet appoval.SRM structure there

  • ICC Camera Profiles?????

    Why does Lightroom not support ICC camera Profiles? How can we preach "complete color management" when we don't START color managed? I realize you can calibrate your camera, which builds a crude profile of sorts, which is a great shortcut for many pe

  • Office Jet 6500 E710n-z won't print black even just replace the ink cartridge with a new one.

    It is the 3rd time to have problem on printing "black" even the ink is not empty (but the level is low, like a quarter left).  In the previous cases, I replaced the cartridge and the problem solved.   The 2nd time was last week.  After I changed the

  • Can't use 3rd party plug-ins

    I've tried to install some third party audio units (from Blue Cat and Digital Fish Pnones) to use in STP 3, but they simply don't show up in the Effects tab. I'm quite sure I've installed them correctly but have I missed something obvious? Thanks!