Java examples for File Path IO:DataOutputStream
Write String as bytes to a file using DataOutputStream
import java.io.DataOutputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static void main(String[] args) { //from w ww .j a v a2s. com 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!"; dos.writeBytes(str); dos.close(); } catch (IOException e) { System.out.println("IOException : " + e); } } }