Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

problem with if-condition

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get the values of fileDirectory and mimeType from a List. The value of mimeType I receive is "text/xml". the first if-condition works fine, however the second if-condition doesn't work at all, and hence I'm not able to read the contents of the file.

The code looks simple, but I'm unable to figure out what the problem is.

Any help appreciated.
Sara

........

String fileDirectory = list.get(0).toString();
String mimeType = list.get(1).toString(); // value is text/xml
//System.out.println("mimeType is "+mimeType);

//if (fileDirectory != null && mimeType != null)
{
//System.out.println("mimeType is "+mimeType);
String filePath = "c:\\" + fileDirectory + "\\";
fileName = filePath + fileName;

if (mimeType == "text/xml")
{
//read file contents....
}

........
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using this:

 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should read up on the difference between the == operator and the equals() method. In general, the == operator will not behave the way you expect when comparing objects. Use the equals() method instead.

Layne
 
Sara Tracy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
equals() worked.
thanks Corey and Layne !

-Sara
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic