Created
October 10, 2018 21:04
-
-
Save Shtaba09/ad63d2f86a8f2b8604609b99730e7e9a to your computer and use it in GitHub Desktop.
Смена кодировок файла
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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