In application, there is one utility, in which user can select file from Hard disk and after selecting file when user click on Submit button, it reads content of file and display data in text field.
Problem:
1. I have stored some data in notepad in Unicode format (At time of saving, selected Unicode in Encoding box)
2. When user select that file and click on submit button it display data in textfield as show in attached image.
1. User select file(in unicode format) from front end (extjs) and click on submit button.
2. That fill will be sent to server side where I read content, generate String
3. send string back to client
4. At client displaying this string in text field where I couldn't read it
I have changed my server side code to read content from file by encoding using UTF-16 and problem solved but now it crated problem to read non-unicode format file.
So, what can be common solution? Which encoding format should I use to read any kind of file?
Your server needs to detect the Content-type of the submitted file (search - this has probably already been written by somebody for your particular server-side language).
Your server needs to detect the Content-type of the submitted file (search - this has probably already been written by somebody for your particular server-side language).
I have written code to get content-type of file but for both the type of file (unicode and non-unicode), I am getting same content-type "text/plain".
I think I need encoding format or type for particular file. Do you have any idea how to get it?
No, it's the charset part of the Content-type that's needed here.
When I have applied code to read content type of selected file, it return me application/octet-stream content type. So it couldn't read the content and utility stop to work and throws exception java.io.UnsupportedEncodingException: application/octet-stream