csv – In Java, what is the char for a tab and how do I pass through a Charset?
csv – In Java, what is the char for a tab and how do I pass through a Charset?
Have you tried char tab = t;
?
The tab character is t
.
The StandardCharsets
type provides a static
field that holds a reference to a UTF-8 Charset
object. You can also use
Charset utf8 = Charset.forName(UTF-8);
csv – In Java, what is the char for a tab and how do I pass through a Charset?
You seem to be misunderstanding something.
A Charset
is not a character at all. It is a Java object which embodies two things: a character decoding process, and a character encoding process.
The decoding process turns a sequence of byte
s into a sequence of char
s; the encoding process does the reverse. Unicode calls this a character encoding. The most commonly used, and by far, is UTF-8 (UTF stands for Unicode Transformation Format).
It is necessary to specify that to the CSV reader constructor because the contents of the file are, ultimately, bytes; the CSV reader needs to know how it will decode these bytes into char
s, therefore it needs to be told which decoding process to use, and in Java, this means passing it a Charset
object.
For more information, see CharsetEncoder
and CharsetDecoder
.
As to what the tab character constant is, you have been told the answer already so this will not be repeated here.