Android复制assets文件到SD卡

package com.mycompany.myapp3;

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import java.io.*;

public class MainActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
	{
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
		try
		{
			copyFileFromAssetsToSDCard();
		}
		catch (Throwable e)
		{}
    }
	public void copyFileFromAssetsToSDCard()throws Throwable{
		InputStream inStream=getAssets().open("my.zip");
		String filePath=android.os.Environment.getExternalStorageDirectory()
			.getAbsolutePath()+"/"+"my.zip";
		OutputStream outStream=new FileOutputStream(filePath);
		byte[]buffer=new byte[1024];
		int length=inStream.read(buffer);
		outStream.write(buffer,0,length);
		outStream.flush();
		inStream.close();
		outStream.close();
	} 
}

版权声明:本文为AIDE教程网原创文章,转载请附上原文出处链接和本声明
本文链接: https://www.aidemx.cn/300.html

梦雪

专注于AIDE教程分享

    留下你的评论

    *评论支持代码高亮<pre class="prettyprint linenums">代码</pre>

    相关推荐