Sitemap

Amicuk Programming Answers

Problem working with binary file

2015-10-11   Views:1

Advertisement

Hi, I have two seperate programs. The first one: *Reads a  PDF file from disk via InputStreamReader.read(char[]) *converts it to s String [String.valueOf(char[])] connects to other program using Socket and writes the string's bytes to the OutputStrea

Hi,
I have two seperate programs.
The first one:
*Reads a  PDF file from disk via InputStreamReader.read(char[])
*converts it to s String [String.valueOf(char[])]
connects to other program using Socket and writes the string's bytes to the OutputStream of the Socket (socket.getOutputStream().write(string.getBytes);)
Second one:
*Reads the file from socket via BufferedReader.read(char[])
*converts it to a string via String.valueOf()
*writes it to a file using FileOutputStream.write(content.getBytes())
The problem is:
If the secong program is running on Win2K,the PDF file is opened with no errors but the pages are all blank.But everything is OK if it is running on Unix(IBM AIX java ver 1.3.1)
First program is always on Win2K.
I compared the win2k and unix PDF files,some nonprintable chars are displayed as ? in the win2K one,
what can be the reason? why does the same problem not occur on Unix?
Some problems are mentioned on web/forums but these are related with browsers or servlets which I am not using in this case.
Thanks in advance,

The replay answer
Advertisement
PDF is a binary file.
You're doing 1 of 2 possible things wrong....
1) trying to read a binary file as a text file ( string )
You can't "just read" a binary file as a text file to extra the strings.
You need to get the binary format, and parse it's format properly to extract the
string data.
2) trying to send a binary file across a socket as a string
You need to read the PDF file as an array of bytes and send them across
the socket as such. Trying to convert binary data to characters / strings
is wrong. characters get converted to and from native encoding schemes to
unicode.... among other problems.
regards,
Owen

Go to See the other 6 answers

Problem working with binary file

Category:DefaultRelease time:2015-10-11Views:130

Hi, I have two seperate programs. The first one: *Reads a  PDF file from disk via InputStreamReader.read(char[]) *converts it to s String [String.valueOf(char[])] connects to other program using Socket and writes the string's bytes to the OutputStrea[More]

Urgent - pls help - Problem while inserting binary file into Oracle DB

Category:DefaultRelease time:-0001-11-30Views:130

Hi, I am trying to insert binary files into a Blob column in a Oracle 10G table. The binary files would be uploaded by the web users and hence come as multipart request. I use apache commons upload streaming API to handle it. Finally i am getting a i[More]

Binary file readed from Labview and Borland C++ v.5

Category:DefaultRelease time:-0001-11-30Views:130

Hi Everybody! My problem is reading binary file from Labview 7.0 and Borland C++ version 5 is not the same. Only one difference is "space". Reading from Labview I got "00" (decimal) and reading from Borland C++ I got "32". I[More]

Problem when streaming out a binary file

Category:DefaultRelease time:2015-10-11Views:130

Hi, I am trying to stream out a binary file to an output stream (not a file, but a socket). My file is a gzip file, and I was initially simply trying to open the file, read it to a a byte array, and writing it out to my output stream. However, I got[More]

Problems with binary files

Category:DefaultRelease time:2015-10-11Views:130

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[More]

Binary file problem (Read a specific Stream)

Category:DefaultRelease time:-0001-11-30Views:130

Hi Guys , I have a problem , I want to read a binary files but not the whole binary file. I only want to read one stream. Forexample , I have a binar files which has 5 streams. If I only want to read one of the stream what should i do ? How do i get[More]

Problems writing a structured binary file...

Category:DefaultRelease time:-0001-11-30Views:130

Hi Folks, I've been working with one of my students to convert this matlab routine into a VI to no avail: fwrite(fout,version,'char'); fwrite(fout,nchar_text,'short'); % convert wave_text into array of ascii integers fwrite(fout,wave_text,'char'); %[More]

Problem saving 2D array to binary file

Category:DefaultRelease time:-0001-11-30Views:130

I am getting some strange results when trying to write a transposed 2D array of Unisgned 8-bit data to a binary file. Attached is an example program ("071026_ArraySave_Bug.vi") which demonstrates the suspicious behavior. The program generates a[More]

Problem rendering certain bytes when reading binary file

Category:DefaultRelease time:-0001-11-30Views:130

I have a two part problem. I am trying to read files of any type from a client and transfer them over a pipe to a UNIX host running a C API. I have this process working for text data just fine however when I try and submit binary data there appears t[More]

Getting problem while editing a binary file

Category:DefaultRelease time:-0001-11-30Views:130

Hi All, I am trying to edit a binary file using Java.The file contain a string that I have to replace with some other string.For exanple let us assume following is the content of the file - õgëÓÌ©™ÿÿ ABC õgëÓÌ©™ÿÿ Here, I have to replace this ABC(a[More]

Binary File IO DLL Problem

Category:DefaultRelease time:-0001-11-30Views:130

Hiii     I have developed one Binary file Read/Write Vi..  and then i have convert that vi in to DLL......     Now i tested that DLL Vi  it is showing an error No 74. Actually for Binary write i will convert the Input cluster to Flattern to String an[More]

Hot
Hi, I've just purchased iTunes Match and I would like to set it up to all devices in my apartment. I've read that you can set it up up to 10 devices. My situation: I have MacBook Pro, iPhone 4 and iPad with my Apple ID. My wife has her MacBook Pro an [More]
This is an accessibility feature I once had and now can't remember how to do it. It allowed me to enter a number rather than clicking on a link*Mouseless Browsing: https://addons.mozilla.org/firefox/addon/mouseless-browsing/Read other 2 answers [More]
my office recently changed printers to a canon imagepress C1+ and i upgraded to a new computer running 10.6.3. we have downloaded and installed the latest driver from canon. the "full properties" glitch is mentioned at [url="http://discussi [More]
Hi, We faced with a problem while using firefox browser on linux client. The problem is browser cannot send selected item index into the BSP application in OnInputProcessing event, but we do not have any problem with IE7, on the same process. We are [More]
Hi all, I already setup a 2 node oracle 11gr2 rac and setup is installaed fine. in baseline testing insert sessions are not failovering to the node1. scenario i do as follows. Scenario 1 - We ran an insert query in both Nodes and unplugged the Node2 [More]
My phone has version 13.0.0003 on it, nokia web is telling me i can update to 21.00.00 or some thing like that but the updater software tells me my phone is up to date can any one help.SIM-locking and branding are two totally different things. If you [More]
I was trying to install Windows 7 using boot camp and received the message that my hard disk drive had the wrong format.  I was able to eject the windows install disk, but now the only message I get is No bootable device - insert boot disk on a black [More]
I can't connect to my emails icloud imapHello holgerdeh, The article linked below provides information that can help identify and correct the source of this issue. OS X Mail: Troubleshooting sending and receiving email messages http://support.apple.c [More]
I didn't join any data plans (i just use wifi to connect to the internet), can i use the apps? The sales told  me that even not joining those data plans, i can still download the apps through wifi and the apps can function nornally. However, i've tri [More]
I'm trying to do a reinstall and I'm running into problems.  I select my packages then chose Install Packages then get an error that Package Install Failed. I can only see a few errors on /dev/vc/5 but I'm getting a whole list that says /x11/aterm: n [More]