安卓开发之生成cache目录和files目录

package com.lidaochen.test;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import java.io.File;
import java.io.FileOutputStream;


public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    // 生成cache目录
    public void click1(View v)
    {
        try
        {
            File file = new File(getCacheDir(), "info.txt");
            FileOutputStream fos = new FileOutputStream(file);
            fos.write("Hello World!".getBytes());
            fos.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    // 生成files目录
    public void click2(View v)
    {
        try
        {
            FileOutputStream fos = openFileOutput("info.txt", 0);
            fos.write("Hello Java!".getBytes());
            fos.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

 

安卓开发之生成cache目录和files目录

上一篇:Android自定义View之(一)新手都能看懂的Android View绘制流程


下一篇:启动错误笔记:DruidDriver] but failed to unregister it when the web application was stopped,To prevent a memory leak, the JDBC Driver has been forcibly unregistered.