它创建了一个样本字符缓冲器,开始生成一个String,然后用getChars( )方法提取字符数组。然后该例创建并写文件。复制代码
- import java.io.FileWriter;
- public class FileWriter1{
- public static void main(String[] args) throws Exception{
- String str = "hello world welcome nihao hehe";
- char[] buffer = new char[str.length()];
- str.getChars(0, str.length(), buffer, 0);
- FileWriter f = new FileWriter("file2.txt");
- for(int i = 0; i < buffer.length; i++)
- {
- f.write(buffer[i]);
- }
- f.close();
- }
- }
| 欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |