aspose file tools*
The moose likes Java in General and the fly likes problem with if-condition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "problem with if-condition" Watch "problem with if-condition" New topic
Author

problem with if-condition

Sara Tracy
Ranch Hand

Joined: Jan 06, 2006
Posts: 45
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....
}

........
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Try using this:



SCJP Tipline, etc.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
Sara Tracy
Ranch Hand

Joined: Jan 06, 2006
Posts: 45
equals() worked.
thanks Corey and Layne !

-Sara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with if-condition
 
Similar Threads
Problems redirecting user from servlet
getWriter and getOutputStream
Update applet text runtime
How to open all the downloading douments in browser
How to download csv file