private static String replaceChars(String str){
  StringBuffer buf=new StringBuffer(str);
  int length=buf.length();
  for (int i=0; i < length; i++) {
    char currentChar=buf.charAt(i);
    if (currentChar == ' ') {
      buf.setCharAt(i,'%');
      buf.insert(i + 1,"20");
      length=length + 2;
      i=i + 2;
    }
 else     if (currentChar == '\\') {
      buf.setCharAt(i,'/');
    }
  }
  return buf.toString();
}

private static String replaceChars ( String str ) { StringBuffer buf = new StringBuffer ( str ) ; int length = buf . length ( ) ; for ( int i = 0 ; i < length ; i ++ ) { char currentChar = buf . charAt ( i ) ; if ( currentChar == ' ' ) { buf . setCharAt ( i , '%' ) ; buf . insert ( i + 1 , "20" ) ; length = length + 2 ; i = i + 2 ; } else if ( currentChar == '\\' ) { buf . setCharAt ( i , '/' ) ; } } return buf . toString ( ) ; }
replace spaces with " % 20 " and backslashes with forward slashes in the input string to generate a well - formed uri string .
