我想检查SD卡上是否存在文本文件.文件名是mytextfile.txt.以下是代码:
FileOutputStream fos = openFileOutput("sdcard/mytextfile.txt", MODE_WORLD_WRITEABLE);
Run Code Online (Sandbox Code Playgroud)
如何检查此文件是否存在?
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.net.URLEncoder;
import com.google.gson.Gson;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
public class SampleActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageButton button = (ImageButton) findViewById(R.id.imageButton1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
doSomething();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public void doSomething() throws Exception {
EditText search2 = (EditText)findViewById(R.id.editText1);
TextView urltext = …Run Code Online (Sandbox Code Playgroud) 我有以下空白
protected void onPaymentSuccess(PaymentResponse response) {
// Stuff...
}
Run Code Online (Sandbox Code Playgroud)
我想在一个空格中保存一个字符串,例如
String key = "JHIJHFEIRUFHEURFGEU5";
Run Code Online (Sandbox Code Playgroud)
我希望能够在手机重启,关闭应用程序后再次检索它(此字符串将保存到手机中).