FileOutputStream fos = new FileOutputStream("/path/to/file.txt");
String data = "Hello, World!"; fos.write(data.getBytes());
fos.close();
import java.io.FileOutputStream; import java.io.IOException; public class WriteToFile { public static void main(String[] args) { FileOutputStream fos = null; try { fos = new FileOutputStream("/path/to/file.txt"); String data = "Hello, World!"; fos.write(data.getBytes()); System.out.println("文件写入成功!"); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fos != null) { fos.close(); } } catch (IOException e) { e.printStackTrace(); } } } }
本文为翻滚的胖子原创文章,转载无需和我联系,但请注明来自猿教程iskeys.com