主要是想把Edittext获取的三个字符串存到information中 但是每次都不行 求助!!
package Main.com;import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.EditText;public class Two extends Activity{ private EditText text1;
private EditText text2;
private EditText text3;
private Button button5;
public String string1;
public String string2;
public String string3;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.two);
text1 = (EditText)findViewById(R.id.editText1);
text2 = (EditText)findViewById(R.id.editText2);
text3 = (EditText)findViewById(R.id.editText3);
button5 = (Button)findViewById(R.id.button5); button5.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
string1 = text1.getText().toString();
string2 = text2.getText().toString();
string3 = text3.getText().toString();
String line = string1+" "+string2+" "+string3;
try {
File file = new File("information.txt");
FileWriter fileWriter= new FileWriter(file); fileWriter.write(line);
fileWriter.close();
System.out.println(line);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}}
package Main.com;import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.EditText;public class Two extends Activity{ private EditText text1;
private EditText text2;
private EditText text3;
private Button button5;
public String string1;
public String string2;
public String string3;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.two);
text1 = (EditText)findViewById(R.id.editText1);
text2 = (EditText)findViewById(R.id.editText2);
text3 = (EditText)findViewById(R.id.editText3);
button5 = (Button)findViewById(R.id.button5); button5.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
string1 = text1.getText().toString();
string2 = text2.getText().toString();
string3 = text3.getText().toString();
String line = string1+" "+string2+" "+string3;
try {
File file = new File("information.txt");
FileWriter fileWriter= new FileWriter(file); fileWriter.write(line);
fileWriter.close();
System.out.println(line);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}}
解决方案 »
- 一个Activity中的多个View怎么切换啊?
- 当手机处于待机状态下(屏幕没光+已锁屏),比如长按菜单键或返回键,怎么打开一个应用程序
- AlertDialog.Builder多选项对话框
- 源码里面:屏幕锁定提示音的相关实现代码是在哪里实现的啊?
- 服务器端如何及时的响应android客户端的请求?类似短信的,怎么实现?
- android 上如何通过SDL开发音视频播放功能
- 求助,apk 安装问题
- android 服务器端怎么做?
- setDisplayHomeAsUpEnabled(true); 为什么没有反应= =
- Android studio simple adapter
- ndk中.c和.cpp文件一起编译
- 汉字识别 问题
将你的File file = new File("information.txt")改成File file = new File("/mnt/sdcard/information.txt")试试。