Amir Azizkhani
Amir Azizkhani

Reputation: 1813

FileOutputStream set encoding with write byte to file

i have a csv file that i save it with utf-8 encoding like below: reference

FileOutputStream fileOut =fileOut = new FileOutputStream(file, true);
       
/*utf-8 setting*/
fileOut.write(0xef);
fileOut.write(0xbb);
fileOut.write(0xbf);

 /*append another string*/
 PrintWriter printWriter = new PrintWriter(fileOut);
 printWriter.write(...);
    

i write string to file and it work correctly with UTF-8 encodeing.

my question is :

  1. anyone know what is this bytes?
  2. how can change it to another encoding like cp1256?
  3. is a list that provide all encoding for that?

UPDATE: assume that i save huge string data that create in pagination and i can not store this size of data in one time.

thanks

Upvotes: 0

Views: 414

Answers (1)

Mirko
Mirko

Reputation: 1552

Why you don't use the FileUtils from Apache Commons? This will make your life much easier. ;-)

And, If you want to covert the content, have a look here: Encoding conversion in java

<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.8.0</version>
</dependency>

Upvotes: 2

Related Questions