java - Android: Showing Spanish (among other) characters read from file -


I know that many such questions are similar, but they provide either a very specific case-specific solution I do not agree with my problem or just do not work.

I have a multi-language app that downloads some information from the internet and stores it later in the file. How it is stored:

  Public Static zero throws stringsofofile (string string, file file) IOException {if (! File.exists ()) {file.createNewFile (); } FileOutputStream outputStream = New FileOutputStream (file); OutputStream.write (string.getBytes ("UTF-8")); OutputStream.close (); }   

But later, when the Spanish version of the file is read, the app shows special characters, such as ±, as I-ve has a black diamond with a question mark It was tried:

  • Download the information in your computer to check that the file is OK and put it manually in the app so that it can be read instead of downloading itself. The file is fine, but no changes are shown in the app.
  • Replace the argument given by "ISO 8859-1", but the only difference in the result is that this time strange character is a regular question mark.
  • To view this properly, copy the downloaded file from the device to the computer once, and it was already incorrect (the "empty square" characters shown in place of the question mark, Which is not shown to open the file).

    So I'm sure the problem is that how can I write a file, because it gets cured from the server, but it is kept wrong. But I've been spending so much time looking at this method and I do not know what the problem is ... any clue?

    Edit: In this way I am downloading the information.

      Public static inputstream display throws off (string Yury) IOException, URIISXXAPSession, server icing upption {HTTPSP response; HTTP Client Client = New DefaultHttpClient (); HttpGet Request = New HttpGet (); Request.setURI (new URI (Yuri)); Feedback = client.execute (request); If (response.getStatusLine (). GetStatusCode () == 409) {new server IiXing exception (); } And {return feedback .getEntity (). GetContent (); }}   

    To convert it to a string object, which I later pass a string string writing method, I

      public static string inputstreameststring (InputStream ) IOException {java.util.Scanner s = new java.util.Scanner (is); String writ; Ret = s.useDelimiter ("\\ A"). HasNext ()? S.next (): ""; Return writ; }   

    I also thought that writeStringToFile might be a problem, but I tried another option which specifies to use UTF-8 and does not work either Does

    You must ensure that the document you are trying to write read in the same charset In your case, if you have a downloadable document then in Spanish, it will probably be written in UTF-8 or ISO-8859-1 , so that you have And to write both related enconding in writing.

    You can use HttpProtocolParams.setContentCharset () to set the corresponding charset for the BasicHttpParams object.

    This can help:



Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -