天天看點

擷取assert檔案路徑

package com.dtbank.app.service;

import java.io.file;

import java.io.fileoutputstream;

import java.io.inputstream;

import java.io.outputstream;

import android.content.context;

import android.os.environment;

import android.util.log;

/**

 * 獲得assets檔案夾下面檔案的路徑

 * @author hb

 *

 */

public class getencryptionfilepath {

class obj{

inputstream in;

string filedir;

string folder;

}

string lock="";

private void getcryptfilepath(obj obj){

synchronized(lock){

try{

if (environment.getexternalstoragestate().equals(environment.media_mounted)) {

file cryptdir= new file(obj.folder);

// log.v("bb","建立的檔案夾:"+obj.folder);

cryptdir.mkdirs();

outputstream os= new fileoutputstream(obj.filedir);

byte[] buf = new byte[1024*10];

int l;

//log.v("bb","開始寫檔案");

inputstream in=obj.in;

while ((l = in.read(buf)) != -1) {

os.write(buf, 0, l);

os.flush();

}  

//log.v("bb","檔案已寫完");

os.close();

in.close();

       }

}catch(exception e){

e.printstacktrace();

//調用此方法  傳入context對象即可

public  void execute(context context){

        inputstream in=null;

        outputstream out=null;

in =(context.getassets().open("mixed.dat"));

string filedir_mixed="/sdcard/.xcloudmixed/mixed.dat";

final obj obj=new obj();

obj.in=in;

obj.filedir=filedir_mixed;

obj.folder="/sdcard/.xcloudmixed";

new thread(){

@override

public void run(){

getcryptfilepath(obj);

}.start();

in =(context.getassets().open("public.dat"));

string filedir_public="/sdcard/.xcloudpublic/public.dat";

final obj obj1=new obj();

obj1.in=in;

obj1.filedir=filedir_public;

obj1.folder="/sdcard/.xcloudpublic";

getcryptfilepath(obj1);