• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Difficulty in getting hold of a binary file!

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 174
Java ME Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your replies.

I fixed it by checking the length of the

pdfData, it was zero, incase of blank file.

Cheers!
 
Ulf Dittmer
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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) ...".
 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic