package com.et.myfiledemo1;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import java.io.File;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
File file = new File("/mnt/sdcard/test");
if(!file.exists()){
try {
//Toast.makeText(this,"文件不存在",Toast.LENGTH_SHORT).show();
Log.i("info","文件不存在");
file.createNewFile();
//Toast.makeText(this,"创建完毕",Toast.LENGTH_SHORT).show();
Log.i("info","文件创建完毕");
} catch (IOException e) {
e.printStackTrace();
//Toast.makeText(this,"创建失败",Toast.LENGTH_SHORT).show();
Log.i("info","创建失败");
}
}else{
Toast.makeText(this,"文件已经存在",Toast.LENGTH_SHORT).show();
}
}
}