简体   繁体   English

如何添加到我在Android应用程序上创建的文件?

[英]How do I add to the file i created on my android app?

this is my code: 这是我的代码:

FileOutputStream fOut = openFileOutput("things", Context.MODE_PRIVATE); 
fOut.write(thing.getBytes());

everytime i go through this method it erases the previous data in the file and overwrites it with the new one. 每次我使用此方法时,它都会擦除文件中的先前数据,并用新的数据覆盖它。 I don't want this to happen because I want the text to be added Thanks for your help. 我不希望发生这种情况,因为我希望添加文本,谢谢您的帮助。

Add the flag MODE_APPEND : 添加标志MODE_APPEND

FileOutputStream fOut = openFileOutput("things", MODE_APPEND);
fOut.write(thing.getBytes())

other option would be using of course the append() method: 其他选择当然是使用append()方法:

 FileOutputStream fOut = new FileOutputStream(myFile,true);
 OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
 myOutWriter.append("Something new!\n");
 myOutWriter.close();
 fOut.close();

您需要在openFileOutput调用中将MODE_APPEND标志(按位或)添加到MODE_PRIVATE中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android应用程序的“开始”屏幕上添加徽标? - How do I add logo on my start screen in android app? 如何添加我在 setcontentview() 函数中创建的 xml 文件 - How do I add an xml file that I created in the setcontentview() function 如何向在 Android 应用程序中创建的 email 添加超链接? - How can I add a hyperlink to this email being created in Android app? 如何在我的android应用中添加对android 4.4的支持 - How can I add support for android 4.4 in my android app 如何在我的Android应用程序中添加某人的网站链接? - How do I add someone's website link in my Android app? 我找不到通过我的android应用创建的.txt文件 - I can't find the .txt file that I created through my android app 如果我这样做的话,在android中创建的文件将在哪里 - Where will be a file created in android if I do it like this 如何将视频文件(mp4)添加到我的android应用程序中? - How do I add a video file (mp4) into my android application? 如何使用JSON从远程数据库检索数据并显示在android应用程序xml文件中? - How do i retrieve the data using JSON from the Remote Database and display in my android app xml file? 如何向我的新闻应用 ANDROID 添加通知? - How can I add notifications to my news App ANDROID?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM