Ребят,нужно прочитать файл в одной кодировке Windows-1251 и записать в другой UTF-8. В чем у меня ошибка?
public class Solution {
public static void main(String[] args) throws IOException {//Windows-1251 , UTF-8
try(InputStream fin = new FileInputStream(args[0]); OutputStream fout = new FileOutputStream(args[1])){
byte[] buffer = new byte[1000];
int count;
while (fin.available()>0){
count = fin.read(buffer);
String s = new String(buffer, "Windows-1251");
buffer = s.getBytes("UTF-8");
if(count!=-1) fout.write(buffer,0,count);
}
}catch (Exception e){}
}
}package com.javarush.task.task22.task2211;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
/*
Смена кодировки
*/
public class Solution {
public static void main(String[] args) throws IOException {//Windows-1251 , UTF-8
try(InputStream fin = new FileInputStream(args[0]); OutputStream fout = new FileOutputStream(args[1])){
byte[] buffer = new byte[1000];
int count;
while (fin.available()>0){
count = fin.read(buffer);
String s = new String(buffer, "Windows-1251");
buffer = s.getBytes("UTF-8");
if(count!=-1) fout.write(buffer,0,count);
}
}catch (Exception e){}
}
}