how to check file exist in assets folder in android ?
I'm using Android Studio and it doesn't seem like I have a assets folder. So I created one.
I'm using this code to load my fonts :
File pdfFile = null;
try {
pdfFile = new File(new URI(("file:///android_assets/tahoma.ttf")));
if (pdfFile.exists())
Toast.makeText(MainActivity.this,"Exist",Toast.LENGTH_LONG).show();
else
Toast.makeText(MainActivity.this,"No Exist",Toast.LENGTH_LONG).show();
} catch (URISyntaxException e) {
e.printStackTrace();
}
structure for a project in Android Studio 0.5.2:
root-module
|--.idea
|--app
|----build
|----src
|------main
|--------assets
|----------tahoma.ttf
|--------java
|----------source code here
|--------res
|------AndroidManifest.xml
|----build.gradle
buidl.gradle file :
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
sourceSets {
main {
assets.srcDirs = ['assets']
}
}
defaultConfig {
minSdkVersion 11
targetSdkVersion 17
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/android-support-v4.jar')
}
}