将本地的gbk文件流读取变换成utf-8文件
public static void gbk2utf8(String targetFile,String outFile)
{
BufferedReader br = null;
BufferedWriter bw = null;
try
{
InputStream is = new FileInputStream(targetFile);
OutputStream os = new FileOutputStream(outFile);
br = new BufferedReader(new InputStreamReader(is,"gbk"));
String str = "";
bw = new BufferedWriter(new OutputStreamWriter(os,"utf-8"));
while((str = br.readLine())!=null)
{
bw.write(str);
bw.newLine();
}
} catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if(null!=bw)
bw.close();
if(null!=br)
bw.close();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
{
BufferedReader br = null;
BufferedWriter bw = null;
try
{
InputStream is = new FileInputStream(targetFile);
OutputStream os = new FileOutputStream(outFile);
br = new BufferedReader(new InputStreamReader(is,"gbk"));
String str = "";
bw = new BufferedWriter(new OutputStreamWriter(os,"utf-8"));
while((str = br.readLine())!=null)
{
bw.write(str);
bw.newLine();
}
} catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if(null!=bw)
bw.close();
if(null!=br)
bw.close();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}