File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Difficulty in getting hold of a binary file! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Difficulty in getting hold of a binary file!" Watch "Difficulty in getting hold of a binary file!" New topic
Author

Difficulty in getting hold of a binary file!

forums UseR
Ranch Hand

Joined: Feb 24, 2009
Posts: 169
Hello,

I am finding it hard to capture the content of a binary file.

Here is my code:


When the binary file is blank, control still goes into "if" instead of "else"!!!

How should I change the "if" condition so that, whenever the binary file is blank, I wanna execute "else"

Thanks

Srinivas
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35224
    
    7
What is the connection between "myInstance.getBin_File().toString().equals("")" and the "binary file being blank"? What kind of object is returned by the getBin_File() method? If it's a file, then the toString method does not return what you think it returns.

Also note that whenever binary data is involved, you should not be using string methods and string comparisons.


Android appsImageJ pluginsJava web charts
Zandis Murāns
Ranch Hand

Joined: Aug 18, 2009
Posts: 174

Here's a little offtopic, but you should always use "".equals(variable) instead of variable.equals("") to avoid null pointer exceptions.
forums UseR
Ranch Hand

Joined: Feb 24, 2009
Posts: 169
Ulf Dittmer wrote:What is the connection between "myInstance.getBin_File().toString().equals("")" and the "binary file being blank"? What kind of object is returned by the getBin_File() method? If it's a file, then the toString method does not return what you think it returns.

Also note that whenever binary data is involved, you should not be using string methods and string comparisons.


Thanks for your reply.



How should I check if pdfData has any content in it ( I mean if pdfData is blank) ?

Can you please provide me a if condition check code ?


Thanks!

Srinivas
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Zandis Murāns wrote:Here's a little offtopic, but you should always use "".equals(variable) instead of variable.equals("") to avoid null pointer exceptions.

That's where the !(null == ...) check comes in.

Which is also an issue. Never ever ever write !(value == variable). There is an operator for that, !=. Use it: value != variable.
Another thing is the extra pair of brackets in !(myInstance.getBin_File().toString().equals("")). The dot binds stronger than the !, so you can simply write !myInstance.getBin_File().toString().equals("").
forums UseR
Ranch Hand

Joined: Feb 24, 2009
Posts: 169
Thanks for your replies.

I fixed it by checking the length of the

pdfData, it was zero, incase of blank file.

Cheers!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35224
    
    7
srinivas chary wrote:


How should I check if pdfData has any content in it ( I mean if pdfData is blank) ?

Can you please provide me a if condition check code ?

Java arrays have a "length" attribute you can use, so the check would be something like "if (pdfData.length == 0) ...".
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: Difficulty in getting hold of a binary file!
 
Similar Threads
Blank if statement
why the outputis false....
Session lost in Tomcat when POST is done from a remote computer
Java URL Quick & Dirty code
Write a program that reads and writes from binary or text files