java.net.ConnectException: Connection refused

I’m caching images to the persistentdatapath folder after I get them from a URL. Later on I try to get the image from the persistentdatapath with a WWW and it’s giving me the error: java.net.ConnectException: Connection refused. It works fine on PC and IOS, but not on Android, here’s my code:

string filePath = Application.persistentDataPath + product_id + ".png";
			DateTime lastModified = File.GetLastWriteTime(filePath);
			if (!File.Exists(filePath) || (DateTime.Now - lastModified).TotalDays >= 30)
			{
				Debug.Log(File.Exists(filePath));
				WWW www = new WWW(url);
				yield return www;
				productImage.sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0));       
				File.WriteAllBytes(filePath, www.bytes);
			}
			else
			{
				WWW www = new WWW(filePath);
				yield return www;
				productImage.sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0));
			}

I know it’s possible to use File.ReadAllBytes, but this appears to be slower compared to the WWW (tested on PC). And I’m also curious as to what I did wrong, any other solution that’s fast or better for caching is also welcome :). Thanks

You don’t always need a Prefix, but when you do, it is freaking Android…PUT “file://” in front of your Application.persistentDataPath and BOOMED! You got yourself a goodnight sleep! something like this:

Yourpath = “file://”+ Application.persistentDataPath + …;

Sorry for being so dramatic, but this made me mad.

Hi Anne, did you found a soltion for this? I have the same problem :frowning: