所以開始作爲按鈕的問題,只是意味着我的文件有問題。我想將數字保存到我的文件中,並且還選擇了我所選的語言。該languege完美的作品,但是當我試圖做同樣的我的號碼,它只是出問題保存文件不能工作總是android
所以這是我languege文件的
french.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try{
buttonSound.start();
String FILENAME = "LangFile";
String data ="FR";
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(data.getBytes());
fos.close();
FILENAME="TempFile";
data="0";
FileOutputStream fostemp = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fostemp.write(data.getBytes());
fostemp.close();
startActivity(new Intent("com.technopolisapp.LOGOTECHNOPOLIS"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally{
finish();
}
}
});
在這裏,我保存2個字母的按鈕被按下 代碼,這是再次讀取並且作出與選擇的languege按鈕的代碼
try{
String FILENAME = "LangFile";
FileInputStream fos = openFileInput(FILENAME);
byte[] b = new byte[2];
fos.read(b);
fos.close();
if(new String(b).equalsIgnoreCase("NL")){
Tower.setText(classNamesDutch[0]);
Puzzle.setText(classNamesDutch[1]);
Mirror.setText(classNamesDutch[2]);
Tangram.setText(classNamesDutch[3]);
Frog.setText(classNamesDutch[4]);
}
if(new String(b).equalsIgnoreCase("GB")){
Tower.setText(classNamesEnglish[0]);
Puzzle.setText(classNamesEnglish[1]);
Mirror.setText(classNamesEnglish[2]);
Tangram.setText(classNamesEnglish[3]);
Frog.setText(classNamesEnglish[4]);
}
if(new String(b).equalsIgnoreCase("FR")){
Tower.setText(classNamesFrench[0]);
Puzzle.setText(classNamesFrench[1]);
Mirror.setText(classNamesFrench[2]);
Tangram.setText(classNamesFrench[3]);
Frog.setText(classNamesFrench[4]);
}
}catch (java.io.FileNotFoundException e) {
} catch (IOException e) {
e.printStackTrace();
}
現在,這是我的保存和閱讀我的數字代碼
public void Savefile(){
int level=0;
String data;
try{
String FILENAME = "TowerFile";
FileInputStream fos = openFileInput(FILENAME);
byte[] b = new byte[1];
fos.read(b);
fos.close();
if(new String(b).equalsIgnoreCase("1")){
level=1;
}
if(new String(b).equalsIgnoreCase("2")){
level=2;
}
if(new String(b).equalsIgnoreCase("3")){
level=3;
}
if(new String(b).equalsIgnoreCase("4")){
level=4;
}
if(new String(b).equalsIgnoreCase("5")){
level=5;
}
if(level!=1 || level!=2 || level!=3 || level!=4 || level!=5){
FILENAME="TowerFile";
data="een";
FileOutputStream fostemp = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fostemp.write(data.getBytes());
fostemp.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
這是我想讀它
try{
String FILENAME = "TowerFile";
FileInputStream fos = openFileInput(FILENAME);
byte[] b = new byte[1];
fos.read(b);
fos.close();
if(new String(b).equalsIgnoreCase("1")){
button1.setVisibility(Button.GONE);
}
if(new String(b).equalsIgnoreCase("2")){
level=2;
}
if(new String(b).equalsIgnoreCase("3")){
level=3;
}
if(new String(b).equalsIgnoreCase("4")){
level=4;
}
if(new String(b).equalsIgnoreCase("5")){
level=5;
}
}catch (java.io.FileNotFoundException e) {
} catch (IOException e) {
e.printStackTrace();
}
所以,我真的不明白哪裏出了問題,此刻
Ow我用2個頁面之間的數字使用相同的方法,所以我真的覺得很奇怪,它不起作用 – stevedc 2012-04-03 11:26:07