Skip to content

Instantly share code, notes, and snippets.

@Shtaba09
Created October 10, 2018 21:04
Show Gist options
  • Save Shtaba09/ad63d2f86a8f2b8604609b99730e7e9a to your computer and use it in GitHub Desktop.
Save Shtaba09/ad63d2f86a8f2b8604609b99730e7e9a to your computer and use it in GitHub Desktop.
Смена кодировок файла
package com.javarush.task.task22.task2211;
import java.io.*;
import java.nio.charset.Charset;
/*
Смена кодировки
*/
public class Solution {
public static void main(String[] args) throws IOException {
FileInputStream reader = new FileInputStream( new File(args[0]));
FileOutputStream writer = new FileOutputStream(new File(args[1]));
Charset utf8 = Charset.forName("UTF-8");
Charset windows1251 = Charset.forName("Windows-1251");
byte[] buffer= new byte[reader.available()];
reader.read(buffer);
String s = new String(buffer, windows1251);
buffer = s.getBytes(utf8);
writer.write(buffer);
reader.close();
writer.flush();
writer.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment