writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("d:\\order.txt"))); writer.write(str); //如果不手动刷新缓存并且关闭流,很可能文件内容为空 writer.flush(); writer.close();