- package cn.CodeSnippet.snippets.core;
- import java.io.DataOutputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class WriteCharToFileWithDataOutputStream {
- public static void main(String[] args) {
- String filename = "output.txt";
- FileOutputStream fos = null;
- DataOutputStream dos = null;
- try {
- fos = new FileOutputStream(filename);
- dos = new DataOutputStream(fos);
- char c = 'A';
- dos.writeChar(c);
- }
- catch (FileNotFoundException fnfe) {
- System.out.println("File not found" + fnfe);
- }
- catch (IOException ioe) {
- System.out.println("Error while writing to file" + ioe);
- }
- finally {
- try {
- if (dos != null) {
- dos.close();
- }
- if (fos != null) {
- fos.close();
- }
- }
- catch (Exception e) {
- System.out.println("Error while closing streams" + e);
- }
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/031220137695.html
来源: http://www.codesnippet.cn/detail/031220137695.html