import java.nio.CharBuffer; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileNotFoundException; import java.io.IOException; public class Read { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String text = null; String filePath ="E://jsp//JSP范例宝典//11//297//a.txt"; CharBuffer cbuf = null; File file = new File(filePath); try { FileReader fReader = new FileReader(file); cbuf = CharBuffer.allocate((int) file.length()); fReader.read(cbuf); text = new String(cbuf.array()); System.out.println(text); byte [] buff=new byte[]{}; FileOutputStream output=new FileOutputStream("D://ddd.txt"); buff=text.getBytes(); output.write(buff, 0, buff.length); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public static void main(String [] args) { byte[] buff=new byte[]{}; try { String aa="你好123"; buff=aa.getBytes(); FileOutputStream out=new FileOutputStream("D://out.txt"); out.write(buff,0,buff.length); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }