使用DataOutputStream将字符串作为字节写入文件
// 来自 nowjava - 时代Java import java.io.DataOutputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static void main(String[] args) { String strFilePath = "C://Folder//WriteStringAsBytes.txt"; try { FileOutputStream fos = new FileOutputStream(strFilePath); DataOutputStream dos = new DataOutputStream(fos); String str = "This string will be written to file as sequence of bytes!";/*n o w j a v a . c o m - 时代Java 提供*/ dos.writeBytes(str); dos.close();