public void WriteFile(String message) { FileOutputStream out = null; BufferedWriter writer = null; // 将文本转换为字节集 try { out = openFileOutput("myfile", MODE_PRIVATE); writer = new BufferedWriter(new OutputStreamWriter(out)); writer.write(message); Toast.makeText(MainActivity.this,"sss",Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (writer != null) { writer.close(); } } catch (IOException e) { e.printStackTrace(); } } } public String ReadFile(){ StringBuilder sb = new StringBuilder("") ; FileInputStream in = null; BufferedReader reader = null; try { in = openFileInput("myfile"); reader = new BufferedReader(new InputStreamReader(in)); String line = ""; try { while ((line = reader.readLine())!=null) { sb.append(line); } } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } finally { try { if (reader != null) { reader.close(); } } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); }
Android 文件输入读取
最新推荐文章于 2023-04-05 09:51:35 发布