Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve the exception Illegal character in path?

Tags:

android

I am displaying images from an URL using XML parsing and some images are displaying very well, but sometimes I get exception like

Illegal character in path at index 113: http://www.theblacksheeponline.com/party_img/thumbspps/12390867930_15951_186997180114_709920114_4296270_6115611_n[1].jpg

How to solve this problem, please provide some sample code...

like image 308
sivaraj Avatar asked Sep 20 '10 17:09

sivaraj


People also ask

How do you solve illegal characters in path?

You can simply use C# inbuilt function " Path. GetInvalidFileNameChars() " to check if there is invalid character in file name and remove it.

What is Illegal character in path?

The "Illegal characters" exception means that the file path string you are passing to ReadXml is wrong: it is not a valid path. It may contain '?' , or ':' in the wrong place, or '*' for example.

What is an illegal character in Python?

To insert characters that are illegal in a string, use an escape character. An escape character is a backslash \ followed by the character you want to insert.


2 Answers

Special characters need escaping such as %5B for [ and %5D for ]

You can use the java.net.URLEncoder to encode the URL as in

java.net.URLEncoder

URLEncoder.encode(myurltoencode,"UTF-8");

This will not just fix the [ or ] but also other encoding issues

like image 110
mrjohn Avatar answered Sep 29 '22 20:09

mrjohn


use this escape code for [ %5B and for the closing ] use %5D

like image 29
Arthur Rizzo Avatar answered Sep 29 '22 18:09

Arthur Rizzo