aspose file tools*
The moose likes I/O and Streams and the fly likes While replacing char of soap response then it throws error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "While replacing char of soap response then it throws error" Watch "While replacing char of soap response then it throws error" New topic
Author

While replacing char of soap response then it throws error

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 740
Hello,

Can anybody please let me know that why its throwing error for:
str=str.replace("<", "<");
str=str.replace(">", ">");
str9+=str;



That's giving the following error:

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

First let's start with the warning. You shouldn't use classes from packages that start with com.sun, sun or sunw. These classes are for JVM internal use only, and can be modified or removed as Oracle feels fit. Check out Apache Commons instead, they have a base64 class in their Codecs library.

Right, to the errors. String has method replace(CharSequence, CharSequence). StringBuilder and StringBuffer only have method replace(char, char) - there is no method for replacing full Strings. The solution in this case is quite simply - replace in the line first, then append the line:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 740
Thanks Rob Spoor the problems fixed but how can I generalize the following code because its looking odd to use every time line=line.replace("this","toThis")

Thanks again
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Use a map that you initialize once, then iterate over:
Because the map won't change, it's best to make it static, final and immutable:
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 740
Thanks from the bottom of my heart
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

You're welcome
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: While replacing char of soap response then it throws error