Android : call class file from assets

on Tuesday, July 29, 2014


i want to use class in assets


if i put project HelloWorld2 in helloWorld/assets


could i call MainActivity2(helloworld/assets/HelloWorld2/MainActivity2) from MainActivity(helloWorld/src)?


i can read MainActivity2.java in assets but can't execute MainActivity2.java from MainActivity.... :(


=== MainActivity



AssetManager assetManager=getAssets();
InputStream inputStream=null;
try {
inputStream=assetManager.open("HelloWorld2/src/com/example/helloworld2/MainActivity2.java");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

String s= readTextFile(inputStream);
Toast.makeText(getApplicationContext(),"readTextfile : "+ s, Toast.LENGTH_LONG).show();
}
}

private String readTextFile(InputStream inputStream){
ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
byte buf[]=new byte[1024];
int len;

try{
while((len=inputStream.read(buf))!=-1){
outputStream.write(buf,0,len);
}

outputStream.close();
inputStream.close();
}
catch(IOException e){

}
return outputStream.toString();
}

0 comments:

Post a Comment