---
title: "android保存文件"
author: "bcc123hf"
date: "2011-06-27T23:39:03Z"
tags: ["Android"]
categories: ["非技术"]
slug: "android"
draft: false
lastmod: "2011-06-27T23:39:03Z"
id: 1107044
url: "https://bcc123hf.iteye.com/blog/1107044"
---

public static boolean IsSdCard()
	{
		boolean nIsSaveSdCard=false;
		if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
			nIsSaveSdCard= true;
		else
			nIsSaveSdCard= false;
		return nIsSaveSdCard;
	}

public static boolean MakeDirs(String aPath)
	{
		boolean nIsExist=false;
		if (IsSdCard()) {
			File sdCardDir = Environment.getExternalStorageDirectory			File nPath=new File(sdCardDir.getAbsolutePath()+"/"+aPath);
			nIsExist=nPath.exists();
			if(!nIsExist)
				nIsExist=nPath.mkdirs(); 
		}
		else
		{
			File nPath=new File("./"+aPath);
			nIsExist=nPath.exists();
			if(!nIsExist)
				nIsExist=nPath.mkdirs(); 
		}
		return nIsExist;
	}


	public static FileOutputStream GetFileOutStream(String aFileName,boolean aIsApp)
	{
		try {
			if (IsSdCard()) {
				File sdCardDir = Environment.getExternalStorageDirectory																File saveFile = new File(sdCardDir, aFileName);
				FileOutputStream outStream = new FileOutputStream(saveFile,aIsApp);
				return outStream;
			}
			else
			{
				File saveFile = new File("./", aFileName);
				FileOutputStream outStream = new FileOutputStream(saveFile,aIsApp);
				return outStream;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}