1

I am Trying to Send Some Info Before Sending File to My Socket Server Through UTF, When I Send only A File Name :

   File fil=new File(filepath);  
   dos.writeUTF (fil.getName());

it Works fine, But When i Add Some Custom String to It :

  dos.writeUTF((("@REQUEST@ROOM:"+roomName+"@FILENAME:"+fil.getName())));

i get This Error :

 UTFDataFormatException: malformed input UTF Format

Could You Help me Here Please ?

6
  • What's the stack trace? Commented Jul 21, 2014 at 1:08
  • UTFDataFormatException: malformed input UTF Format this is the Log on The Server Dude Commented Jul 21, 2014 at 1:09
  • What is the exception stack trace? Commented Jul 21, 2014 at 1:10
  • there is no Stack Trace on the Exception,Since i Dont Have the Source for jre-8 Commented Jul 21, 2014 at 1:14
  • That statement doesn't make sense. You don't need JRE source code to get a stack trace. Commented Jul 21, 2014 at 1:21

1 Answer 1

1

You don't get that exception when writing. You get it when reading: typically when calling readUTF() when the next thing in the input isn't produced by writeUTF(). In other words, an application protocol error. In this case it isn't produced by what you've posted but by what you haven't posted.

I don't see why you don't write the extended piece of data in separate writes and read it in separate reads, rather than giving yourself the trouble of concatenating and then splitting it up again.

I also don't know what all the extra parentheses are supposed to be for. Don't write redundant syntax.

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

5 Comments

i found the answer, thanks any way, but by the way, the Reason i have appended them togeather is lesser (even a bit) communication, so higher speed
The speed difference won't be measurable but the extra complication and cost and risk of the way you've done it certainly is.
what risk? you mean NPE Exception Posibility?
if thats What You Meant , I have first Assured There is no Way In the Hell the Reuqest be Null :) either ill be Happy to know What You Mean
I mean the risk of the encoding and the decoding not matching up so you have to debug them, which is far lower if you separate them.

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.