11-09-2011 12:14 PM
Hi,
I open a text file (file.txt) and try to save it as a binary (file.bin). It just creates another ASCII file. Both look the same in Notepad. What am I doing wrong?
Thanks!
Shok
Solved! Go to Solution.
11-09-2011 12:18 PM
A "text" file is a binary file. A byte is a character, a character is a byte. What shows on the screen in notepad is determined by the ASCII table mapping.
What did you expect to see differently in your "binary" file when you used Read Text File to read the data and sent the data without changing anything about it to the Write Binary file function?
11-09-2011 12:22 PM
In general text file is binary byte file where each byte is ASCII symbol, so you have the same content. If you would like to get "unreadable" binary file, just convert string to byte array, then perform xor operation. When opened, perform xor operation again and you will get your text back. What you expect to get in general?
Andrey.
11-09-2011 12:23 PM
There is one important difference between writing or reading a binary file versus text, and that is that end-of-line handling. When you write a line to a text file, the write function will write the appropriate end-of-line character, which is different on Windows, Mac, and Unix. This isn't a difference in the file itself, it's a difference in the functions used to access it.
11-09-2011 12:37 PM
Nathan, Not true. The LabVIEW Write text file function writes out exactly what you have in that string. No more, no less. If you want the appropriate end of line character, you have to explicity add it yourself.
11-09-2011 12:42 PM
@Ravens Fan wrote:
Nathan, Not true. The LabVIEW Write text file function writes out exactly what you have in that string. No more, no less. If you want the appropriate end of line character, you have to explicity add it yourself.
It's mostly true. Drop a Write to Text File on a block diagram and right click on it. The "Convert EOL" item is checked by default. Admittedly if you uncheck it, it will write your input exactly, but the default behavior is to convert end of line characters.
11-09-2011 12:49 PM
Let's clarify.
The Write to Text File does not ADD any kind of end of line character. I wrote the data "xx". That is exactly what it put in the file. 2 bytes
Now if you do send data that includes an end of line character in it, "xx\r" (slash code mode, 3 bytes) then it will convert the \r to a \r\n in Windows when the Convert EOL character is setting is on and the file will contain 4 bytes.
11-09-2011 01:04 PM
I guess I was expecting hex data or something.
Thanks!