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(); } } }