我在这个类的 fragment 中:
public class NetworksList extends Fragment{
在我的 onCreate 函数中我有这段代码:
XmlPullParserFactory pullParserFactory;
try {
pullParserFactory = XmlPullParserFactory.newInstance();
XmlPullParser parser = pullParserFactory.newPullParser();
InputStream in_s = getActivity().getApplicationContext().getAssets().open("temp.xml");
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(in_s, null);
Toast.makeText(getActivity().getApplicationContext(), "size: ", Toast.LENGTH_LONG).show();
parseXML(parser);
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
希望我尝试使用它来打开 XML 文件。我的 XML 文件在 Assets 文件夹中,但我得到:
05-08 18:03:11.034 24645-24645/pt.smartgeo.aees W/System.err﹕ java.io.FileNotFoundException: temp.xml
05-08 18:03:11.034 24645-24645/pt.smartgeo.aees W/System.err﹕ at android.content.res.AssetManager.openAsset(Native Method)
05-08 18:03:11.034 24645-24645/pt.smartgeo.aees W/System.err﹕ at android.content.res.AssetManager.open(AssetManager.java:316)
05-08 18:03:11.034 24645-24645/pt.smartgeo.aees W/System.err﹕ at android.content.res.AssetManager.open(AssetManager.java:290)
05-08 18:03:11.034 24645-24645/pt.smartgeo.aees W/System.err﹕ at pt.smartgeo.aees.NetworksList$2.onClick(NetworksList.java:77)
FileNotFound...我如何知道将我的 temp.xml 文件放在哪里,以便我可以在我的 NetworksList 类中打开它?
最佳答案
如果您确定在/assets 文件夹中有文件temp.xml,(必须与/src 处于同一级别和项目中的 /res),只需尝试刷新,F5。
您从 assets 加载文件的方式是正确的:
InputStream is = getApplicationContext().getAssets().open("temp.xml");
关于Android Assets - FileNotFound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23548323/
这个问题已经被问过几次了,但我尝试了提供的解决方案,但仍然没有帮助,所以我提出了一个新问题。gem文件gem'jquery-ui-rails'按照建议,我将gem放在:assets组之外Application.css~*=require_self*=requirejquery.ui*=requirebootstrap-datepicker*=requirejquery.timepicker*=require_tree.*/RailsAssetPipeline根据列出的顺序加载Assets。在这里,我把它排在列表的第2位。Application.css.scss*=require_sel
我正在尝试将我的Rails应用程序部署到heroku,但推送到heroku被拒绝,原因是:“Sprockets::FileNotFound:找不到类型为‘application/javascript’的文件‘jquery’”。I'vealsoattachedascreenshotoftheerror这是我的gemfile:source'https://rubygems.org'git_source(:github)do|repo_name|repo_name="#{repo_name}/#{repo_name}"unlessrepo_name.include?("/")"https:/
我有一个Jenkins安装(版本1.474)在WindowsServerEnterprise2007机器上运行,并且通过Jenkins运行Maven测试目标时遇到问题。我的测试需要读取一个txt文件配置的路径,运行时出现“FileNotFound”异常:path:file:////X:/TESTIN/file.txtjava.io.FileNotFoundException:X:\TESTIN\file.txt(Thesystemcannotfindthepathspecified)atjava.io.FileInputStream.open(NativeMethod)atjava.i
这个问题在这里已经有了答案:AppDomain.Load()failswithFileNotFoundException(2个答案)关闭1年前。我正在尝试使用插件制作应用程序。我有MainLib.dll,我在其中使用1种方法创建了一些通用接口(interface)(让它成为ICommon)。然后,我制作了2个.dlls(plugins),它们引用了MainLib.dll并在某些类中实现了ICommon。此外,我删除了此.dll中的所有引用,System。然后,我创建了一个应用程序,它监视文件夹".\\Plugins"并加载newDomain中的所有.dll,检查.dll中的类型是否实现
为什么我在运行这个程序时会出现这个错误?这发生在随机迭代之后。通常在第8000次迭代之后。publicstaticvoidmain(String[]args){FileWriterwriter=null;try{for(inti=0;i异常发生后,文件不存在。这意味着它正在删除,但FIleWriter会尝试在此之前获取锁,即使它不是多线程程序。是因为Windows删除文件的速度不够快,因此FileWriter没有获得锁定吗?如果是这样,那么file.delete()方法会在Windows实际删除它之前返回吗?我该如何解决它,因为我在对我的应用程序进行负载测试时遇到了类似的问题。编辑1:
好的,我觉得这应该很容易,但显然缺少用Java编写文件的一些基本知识。我有这个:FilesomeFile=newFile("someDirA/someDirB/someDirC/filename.txt");我只想写入文件。然而,虽然someDirA存在,但someDirB(因此someDirC和filename.txt)不存在。这样做:BufferedWriterwriter=newBufferedWriter(newFileWriter(someFile));抛出FileNotFoundException。好吧,呃,不是开玩笑。毕竟我正在尝试创建它。在实例化FileWriter对象
我正在尝试使用以下代码从HDFS读取文件:finalConfigurationconfiguration=newConfiguration();configuration.set("fs.defaultFS","hdfs://localhost:8020/user/training/");FileSystemfileSystem=FileSystem.get(configuration);StringfilePath="hdfs"+"://"+"localhost:8020"+"/user/training/test.txt";FilefileToProcess=newFile(fil
我尝试将本地文件存储在分布式缓存中。该文件存在,但我得到一个文件未找到异常代码片段:DistributedCache.addCacheFile(newURI("file://"+fileName),conf);RunningJobjob=JobClient.runJob(conf);异常(exception):Errorinitializingattempt_201310150245_0066_m_000021_0:java.io.FileNotFoundException:File/Workflow/datadoesnotexistatorg.apache.hadoop.fs.Raw
我在这个类的fragment中:publicclassNetworksListextendsFragment{在我的onCreate函数中我有这段代码:XmlPullParserFactorypullParserFactory;try{pullParserFactory=XmlPullParserFactory.newInstance();XmlPullParserparser=pullParserFactory.newPullParser();InputStreamin_s=getActivity().getApplicationContext().getAssets().open(
我的Web应用程序在Windows上运行。我也想在Linux上运行我的应用程序。我似乎已经克服了大部分问题,例如路径分隔符等。现在真正的问题是,当Java代码尝试打开一个文件时,我得到了FileNotFoundException说Abc.txt而只有abc.txt存在.:(我无法继续将所有文件名更改为小写或大写,因为我有很多文件。在不更改代码的情况下是否有任何可能的方法来避免这种情况? 最佳答案 修复它!从长远来看,您设计的任何规避修复的方案都会变得更糟。 关于java-在Linux上运