2

At the moment I use

serverOutput = new DataOutputStream(socketCliente.getOutputStream());

and then

serverOutput.write(data.getBytes());

and it works fine UNTIL I add any non standard characters (for example ñ) and then as many characters I add, that number of characters are cut from the end of the file and don't arrive.

Full source code is available here in PandroidAgentTentacle.java

http://pandora.svn.sourceforge.net/viewvc/pandora/trunk/pandora_agents/android/src/pandroid/agent/

2
  • 2
    Have you tried specifying a charset name? getBytes(String charsetName) or getBytes(Charset charset). You will also have to specify the charset on the reciever's side. Sending some end-of-data marker would also be handy (or prefix a length). Commented Aug 27, 2012 at 7:52
  • I get this:- The method getBytes(String) in the type String is not applicable for the arguments (Charset) Commented Aug 27, 2012 at 8:09

2 Answers 2

1

The good this with using a DataOutputStream is that you have the writeUTF method that encapsulates all this for you.

Sign up to request clarification or add additional context in comments.

2 Comments

writeUTF adds a BOM that breaks the file being able to be read at the other end
no. it does not add a BOM. It includes the size of the stream. The other end should use readUTF to fetch the proper content. If you cannot use this, you need to explicitly indicate UTF-8 every time you switch from string to bytes.
0

have you tried to use serverOutput.write(data.getBytes("UTF-8")); ?

2 Comments

Well, the default charset on Android is UTF-8, so I don't think this will change anything.
then check the server side, maybe the problem is there, you must read strings like new String(text,"UTF-8");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.