MYYA
Java通过使用I/O文件操作类,来创建输入输出流,将数据保存在file tet文件里面。示例如下:123456789101112131415161718192021222324252627282930313233343536373839404142434445package *&####&*_1_*&####&*; import java.io.File;import java.io.FileOutputStream;import java.io.IOException; public class WriteFileExample { public static void main(String[] args) { FileOutputStream fop = null; File file; String content = "This is the text content"; try { file = new File("c:/newfile.txt"); fop = new FileOutputStream(file); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } // get the content in bytes byte[] contentInBytes = content.getBytes(); fop.write(contentInBytes); fop.flush(); fop.close(); System.out.println("Done"); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fop != null) { fop.close(); } } catch (IOException e) { e.printStackTrace(); } } }}