文件輸入輸出

package cn.un.app.util;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;


public class MyFileOut {

	public static boolean writeOutputStrem(String str){
		boolean  bool = false;
		try {
			InputStream is = new ByteArrayInputStream(str.getBytes("UTF-8"));
			bool = writeOutputStrem(is);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return bool;
	}
	public static boolean writeOutputStrem(InputStream is){
		boolean  bool = false;
		File file = new File("/data/data/cn.un.app/json.txt");
		int len = 0;
		byte[] buf = new byte[1024];
		try {
			if(!file.exists()){
				file.createNewFile();
			}
			OutputStream os = new FileOutputStream(file);
			while((len=is.read(buf))>0){
				os.write(buf, 0, len);
			}
			is.close();
			os.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return bool;
	}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章