Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

How can I know what file's encoding when I read a file use New I/O package???

Hi every body,
When I use NIO (New I/O JDK1.4) to read a file's content.
How can I know exactly file's encoding (example: UTF-8, Cp1252, shift-jis ...) to choose right decoder to decode the file??
Thanks
Best regards.
Hung, Nguyen Thanh.
0
hungnguyenthanh
Asked:
hungnguyenthanh
  • 2
  • 2
1 Solution
 
Venci75Commented:
For the UTF files - you can check for BOM in the beggining of the file:
http://www.unicode.org/unicode/faq/utf_bom.html#22
If your file is in XML format and its first line is like this :
<?xml version="1.0" encoding="UTF-8"?>
you can take the encoding from the line.
In all cases - there is no standard way to find the file encoding.
0
 
hungnguyenthanhAuthor Commented:
Pls help me. Thanks
0
 
Venci75Commented:
???
as I have already mentioned - there is no universal way to determine the file encoding
0
 
hungnguyenthanhAuthor Commented:
But how can I recognize between two encoding file, all not unicode encoding, example: between shift-jis and ansi?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now