如何在Android中写入文件?
可能的重复:
如何在android中创建文件?
我有一个游戏需要用户“登录”。我希望有一个自动登录功能,而不是每次都输入用户名和密码。因此,当用户启动应用程序时,他们所要做的就是按登录按钮,它会自动登录,这样他们就不必每次都输入用户名和密码。我认为我可以编写一个包含用户名和密码的文件,然后应用程序可以从该文件中读取信息,然后将该信息发送到服务器。如何在 Android 中创建文件?那么如何写入该文件呢?我如何从中阅读?我可以用 Java 做 I/O 的事情,所以我知道基础知识,但我不认为这对于 Android 来说是一样的。有人可以引导我完成它吗?
Possible Duplicate:
How to create a file in android?
I have a game that requires the user to "login". Instead of having to type in their username and password everytime, i would there to be a auto-login feature. So when the user starts up the app all they have to do is press a login button and it will log them in automatically so that they dont have to input their username and password everytime. I thought i could write a file containing the username and password and then the app could read from that file and then send that information to the server. How do i create a file in android? How do then write to that file? How do i read from it? I can do I/O stuff in Java so I know the basics but i dont think it is the same for android. Can someone walk me through it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于如此简单的事情,请尝试 SharedPreference。其他选项可以在这里找到:
http://developer.android.com/guide/topics/data/data -storage.html
For something this simple, try a SharedPreference. Other options can be found here:
http://developer.android.com/guide/topics/data/data-storage.html
我同意 ImR 的观点,使用 SharedPreferences 可能更好。但如果您想使用与 Java 非常相似的文件,请查看此页面 示例。
I agree with ImR, it is probably better to use SharedPreferences. But if you want to use a file it is very similar to Java, take a look at this page for a sample.