栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将字符串写入文本文件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将字符串写入文本文件

这是完成的方式。以下示例代码在单击提交按钮后将详细信息保存到文件中:

Submit = (Button) findViewById(R.id.btnSubmit); //Instantiates the button in the onCreate method         Submit.setonClickListener(new onClickListener(){  //Called when the user clicks on the Submit button @Override public void onClick(View v) { // In this case the text to be written is the selected text in a radio button from radioGroup     int Selection = AttendanceGroup.getCheckedRadioButtonId();     // find the radiobutton by returned id      RadioButton radiobutton = (RadioButton) findViewById(Selection);         // write on SD card file data in the text box         try {  //gets the current date since this is an attendance app.  Calendar c = Calendar.getInstance();  //Formats the date a desired  SimpleDateFormat date = new SimpleDateFormat("dd-MM-yy");  String getDate = date.format(c.getTime());  //writes the text to the file named attendance.txt which is created in the phone.  File myFile = new File("/sdcard/Albanapp/Attendance.txt");  FileWriter fOut = new FileWriter(myFile, true);  fOut.append(getDate + "t" + getSelectedName.getSelectedItem().toString() + "t" + radiobutton.getText().toString() + "n");  fOut.flush();  fOut.close();  //Returns a statment to the user showing if the editing of the attendance.txt file was successful or not.    Toast.makeText(getbaseContext(),"Status Saved", Toast.LENGTH_SHORT).show();         } catch (Exception e) {  Toast.makeText(getbaseContext(), "Attendance cannot be saved",          Toast.LENGTH_SHORT).show();         } }        });

希望这可以帮助 :)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/451731.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号