//把其他地方的项目弄到AIDE里经常会出现乱码,用这个就能一键转换编码了
import java.io.*;
import java.nio.charset.Charset;
import java.util.*;
public class Main
{
private static void convertFile (File src, String outputFile) throws IOException
{
char[] buf = new char[1024];
StringBuilder strb = new StringBuilder();
InputStreamReader isr = null;
try
{
isr = new InputStreamReader(new FileInputStream(src), Charset.forName("GBK"));
int readCount = 0;
while (-1 != (readCount = isr.read(buf)))
{
strb.append(buf, 0, readCount);
}
}
finally
{
if (isr != null)
{
try
{
isr.close();
} catch (IOException e)
{
} } }
PrintWriter pw = null;
try
{
pw = new PrintWriter(outputFile, "utf-8");
pw.write(strb.toString());
pw.flush();
}
finally
{
if (null != pw)
{
pw.close();
}
}
System.out.println("转换成功 : " + new File(outputFile).getName());
}
public static void convertDirectory (File src) throws IOException
{
if (src.isDirectory())
{
for (File sub : src.listFiles())
{
convertDirectory(sub);
}
}
else if (src.isFile())
{
convertFile(src, src.getAbsolutePath());
}
}
public static void main (String[] args) throws IOException
{
String inputSrc = "转换路径";//使用前修改为你要转换的路径
File src = new File(inputSrc);
convertDirectory(src);
System.out.println("\n-------转换完成-------");
}
}
import java.io.*;
import java.nio.charset.Charset;
import java.util.*;
public class Main
{
private static void convertFile (File src, String outputFile) throws IOException
{
char[] buf = new char[1024];
StringBuilder strb = new StringBuilder();
InputStreamReader isr = null;
try
{
isr = new InputStreamReader(new FileInputStream(src), Charset.forName("GBK"));
int readCount = 0;
while (-1 != (readCount = isr.read(buf)))
{
strb.append(buf, 0, readCount);
}
}
finally
{
if (isr != null)
{
try
{
isr.close();
} catch (IOException e)
{
} } }
PrintWriter pw = null;
try
{
pw = new PrintWriter(outputFile, "utf-8");
pw.write(strb.toString());
pw.flush();
}
finally
{
if (null != pw)
{
pw.close();
}
}
System.out.println("转换成功 : " + new File(outputFile).getName());
}
public static void convertDirectory (File src) throws IOException
{
if (src.isDirectory())
{
for (File sub : src.listFiles())
{
convertDirectory(sub);
}
}
else if (src.isFile())
{
convertFile(src, src.getAbsolutePath());
}
}
public static void main (String[] args) throws IOException
{
String inputSrc = "转换路径";//使用前修改为你要转换的路径
File src = new File(inputSrc);
convertDirectory(src);
System.out.println("\n-------转换完成-------");
}
}