android在当前app该文件下创建一个文件夹

简介:
 






/*********************************************************************

 * Author  : Samson  * Date    : 04/22/2014  * Test platform:  *              3.11.0-12-generic #19-Ubuntu  *              GNU bash, version 4.2.45  * *******************************************************************/ 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 # 

版权声明:本文博客原创文章,博客,未经同意,不得转载。







本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4663566.html,如需转载请自行联系原作者


相关文章
|
15天前
|
Shell Android开发
Android系统 adb shell push/pull 禁止特定文件
Android系统 adb shell push/pull 禁止特定文件
22 1
|
1天前
|
Android开发
Android APP 隐藏系统软键盘的方法
Android APP 隐藏系统软键盘的方法
6 0
|
1天前
|
Android开发
Android修改默认system/bin/下可执行程序拥有者和权限,使用实例,只有root和系统app权限才能执行某个命令。
Android修改默认system/bin/下可执行程序拥有者和权限,使用实例,只有root和系统app权限才能执行某个命令。
9 0
|
1天前
|
Android开发
android 12 U盘 /mnt/media_rw 下读取文件异常 没有权限
android 12 U盘 /mnt/media_rw 下读取文件异常 没有权限
6 0
|
1天前
|
XML Android开发 数据安全/隐私保护
android 11后文件读写访问权限申请
android 11后文件读写访问权限申请
8 0
|
1天前
|
JSON Android开发 数据格式
Android 打开系统文件管理器,并返回选中文件的路径
Android 打开系统文件管理器,并返回选中文件的路径
7 0
|
15天前
|
Java Android开发 C++
Android源代码定制:MK文件执行顺序|属性覆盖
Android源代码定制:MK文件执行顺序|属性覆盖
18 2
Android源代码定制:MK文件执行顺序|属性覆盖
|
15天前
|
存储 Java API
Android系统 文件访问权限笔记
Android系统 文件访问权限笔记
52 1
|
15天前
|
移动开发 Java Unix
Android系统 自动加载自定义JAR文件
Android系统 自动加载自定义JAR文件
40 1
|
15天前
|
XML Java Android开发
Android系统 添加动态控制屏幕方向、强制APP横竖屏方向
Android系统 添加动态控制屏幕方向、强制APP横竖屏方向
30 1