Sitemap

Amicuk Programming Answers

Problem working with binary file

2015-10-11   Views:0

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
If you're getting into ADF security, you're probably going to want to get rid of that ugly default login.html page. I mean, it gets the job done, but we want something a little better. And if you want something a little better and you're using JDev 1 [More]
Just wondering if there are any additional themes that are available to purchase and download for the program?  Thank you.LizzyLove As to your thread question..not that I have ever run into. You can customize the Adobe Instant Movies by creating an I [More]
I have been sent 2 pdf files. I have windows 7.  Both files open, both can be saved.  One I can print but the other when I try to print by any means just flashes off the screen and Adobe Reader shuts down.  Some times I get a message that Adobe has a [More]
Hi, not really an actionscript expert but is there a way of calling a function on a different layer. You might ask why I'm not placing the actionscript in the same layer!? I have created a lot of code and at the moment with my experience I'm finding [More]
Hi all, We have 2 ACS 4.2.1 servers in Windows 2003 with SP2 installed. We have updated the first ACS to the latest patches for Windows. After that we started having problems. CSRadius either stops by itself or when some time passes we get the follow [More]
Hi! Is it possible to design a custom data table (output) with the desired attributes of a data control? For example, dragging the attributes and placing them in a specific cell of a table(html) ?Hi, you can use Trinidada tablelayout, rowLayout and c [More]
Our band recently had a videographer record our performance using two panasonic hd cameras: AG-HVX200 and HPX170. Both were set to hd 720 X (?) at 30 fps. All files were saved as .mov files. We can't see them at all. We were told that they were desig [More]
Hey there 1 Month ago I bouth a single-app month-to-month license for Adobe After Effects CC. Currently My Creative Cloud app shows that my software was installed 29 days ago, this will probably change after a couple of hours to 30 days My question i [More]
Hi Friends, I am facing problem in doing settlement from Top level WBSE to AUC. I feel I have done the required settings. I am not able to generate settlement rule for the top level WBSE. Please help me out. I would appreciate some screen-shot help f [More]
Hi, I'm interested in learning more about java chat. How it works and how to do all the special functions. It seems really popular and I feel like a novice because I only know how to type and log in. Oh, pardon me, I'm Eanus. I like fishing, history [More]