zoukankan      html  css  js  c++  java
  • 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 # 

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

  • 相关阅读:
    UVa OJ 102 Ecological Bin Packing (生态学装箱问题)
    最小生成树 zoj1586 QS Network
    最小生成树&并查集 POJ 1861 Network
    最小生成树&并查集POJ 1287 Networking
    2012年亚洲长春区域赛:K Yukari's Birthday
    最小生成树 ZOJ 1203 Swordfish
    HDU 2639 Bone Collector II
    POJ2528 Mayor's posters(区间替换&&线段切割)
    POJ2777 Count Color(区间修改&&懒惰标记&&位运算)
    (转)有关如何入门ACM
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4663566.html
Copyright © 2011-2022 走看看