package com.example.listfile; import java.io.File; import java.io.IOException; import android.app.Activity; import android.content.Context; import android.widget.TextView; import android.os.Bundle; import android.os.Process; public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int myProcessID = Process.myPid(); File yygypath = this.getFilesDir();//this.getCacheDir(); String yygypathstr = yygypath.toString(); File file = new File(yygypath, "yygytest"); try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } yygypathstr = yygypathstr + " pid is " + myProcessID; TextView tv = new TextView(this); tv.setText(yygypathstr); setContentView(tv); } public void onDestory() { super.onDestroy(); this.finish(); android.os.Process.killProcess(android.os.Process.myPid()); System.exit(0); } }
主要是这两个函数:
this.getFilesDir(); 这个是得到当前app目录下的files目录路径
this.getCacheDir(); 这个是得到当前app目录下的cache目录路径
结果:
adb shell result:
root@generic:/data/data/com.example.listfile/files # ll
-rw------- u0_a53 u0_a53 0 2014-04-21 13:38 yygytest
root@generic:/data/data/com.example.listfile/files #
查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索android
, 目录
, textview
, this
, process
import
360无法创建当前目录、android 创建目录、android 创建多级目录、android 创建目录失败、android 创建文件目录,以便于您获取更多的相关知识。