openFileOutput FileNotFoundException异常 [英] openFileOutput FileNotFoundException

查看:250
本文介绍了openFileOutput FileNotFoundException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的一周noob问题。我在寻找更一般的炒作不是具体的code,也许希望Android的人正在看,并可能纠正此:

This is my noob question for the week. I'm looking more for general speculation than specific code and maybe hoping the Android folks are watching and could correct this:

SDK文档Context.openFileOutput说:

the SDK documentation for Context.openFileOutput says:

打开这个背景下的应用程序包写入相关的私人文件。创建该文件,如果它不存在。

Open a private file associated with this Context's application package for writing. Creates the file if it doesn't already exist.

好吧,这听起来不错。我可以创建一个文件。除了这种方法也抛出FileNotFoundException异常,那么显然有什么不妥。为什么一个功能是的应该的到,如果没有找到抛出一个异常创建一个文件,如果没有找到???文件

Ok, that sounds good. I can create a file. Except this method also throws a FileNotFoundException, so apparently something is amiss. Why would a function that is supposed to create a file if it's not found throw an exception if the file is not found???

有点儿违背了整个创建文件...的事情,不是吗?

Kinda defeats that whole "Creates the file..." thing, doesn't it?

推荐答案

我要道歉,跳跃之前,我看了就这一个。我有点慌了,而阅读文档。经过一些测试,我发现 openFileOutput()呢,其实,工作通告和的创建一个文件,如果没有找到,而不仅仅是抛出FNF例外,因为我害怕。显然,FNF掷中加入的情况下的活动的应用程序的目录不存在

I have to apologize for leaping before I looked on this one. I kinda panicked while reading the documentation. After some testing, I found that openFileOutput() does, in fact, work as advertised and will create a file if it's not found, not just throw an FnF exception as I feared. Apparently, the FnF throw was added in case the Activity's application directory does not exist.

此外,我的道歉,但希望,这可能帮助别人谁是文档相混淆。

Again, my apologies but hopefully, this might help others who are confused by the documentation.

这篇关于openFileOutput FileNotFoundException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆