读取txt文件内容并存储在数组中(Reading txt file contents and storing in array)
我一直在尝试读取txt文件。 txt文件包含例如行
First Line Second Line Third Line . . .
现在我使用以下代码
InputStream is = null; try { is = getResources().getAssets().open("myFile.txt"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } ArrayList<String> arrayOfLines = new ArrayList<String>(); Reader reader; //char[] buffer = new char[2048]; try { Reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); int n; while ((n = reader.read()) != -1) { } }catch (Exception e) { e.printStackTrace(); }
我的问题是,我如何在arrayList中存储每一行。 Ofc我们必须使用
"/n"
检查但是如何检查。I have been trying to read a txt file. The txt file contains lines e.g
First Line Second Line Third Line . . .
Now I am using following code
InputStream is = null; try { is = getResources().getAssets().open("myFile.txt"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } ArrayList<String> arrayOfLines = new ArrayList<String>(); Reader reader; //char[] buffer = new char[2048]; try { Reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); int n; while ((n = reader.read()) != -1) { } }catch (Exception e) { e.printStackTrace(); }
My question is, how can i store each line in the arrayList. Ofc We have to use a check for
"/n"
but how.
原文:https://stackoverflow.com/questions/11918747
更新时间:2022-07-04 06:07
最满意答案
我对基本
<cfexit>
行为的回忆是:
- 在CFC中使用,
cfexit
退出cfc函数。 但是继续处理呼叫页面。- 如果在函数内,但不在cfc内,则处理中止。
更新:我刚刚确认了CF9.0.1下的行为
结果(使用cfexit)
Start calling page Called test() Finish calling page Called on requestEnd
结果(使用cfabort)
Start calling page Called test() Called on requestEnd
Test.cfm
Start calling page <br /> <cfset createObject("component", "Foo").test()> Finish calling page <br />
Foo.cfc
<cfcomponent> <cffunction name="test" output="true"> Called test()<br /> <cfexit> </cffunction> </cfcomponent>
My recollection of how a basic
<cfexit>
behaves is:
- Used within a CFC,
cfexit
exits the cfc function. But processing of the calling page continues.- If within a function, but NOT inside a cfc, then processing is aborted.
Update: I just confirmed that behavior under CF9.0.1
Results (using cfexit)
Start calling page Called test() Finish calling page Called on requestEnd
Results (using cfabort)
Start calling page Called test() Called on requestEnd
Test.cfm
Start calling page <br /> <cfset createObject("component", "Foo").test()> Finish calling page <br />
Foo.cfc
<cfcomponent> <cffunction name="test" output="true"> Called test()<br /> <cfexit> </cffunction> </cfcomponent>
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
如果你的每一个CFC实例都是单例(即你只需要在你的应用程序中使用它的一个实例),那么你肯定希望查看Dependancy Injection。 CF有三种主要的Dependancy Injection框架; ColdSpring,WireBox和DI / 1。 我建议你看看DI / 1或WireBox,因为ColdSpring还没有更新一段时间。 DI / 1的wiki页面位于: https : //github.com/framework-one/di1/wiki/Getting-Started-with- ...
-
我对基本
行为的回忆是: 在CFC中使用, cfexit退出cfc函数。 但是继续处理呼叫页面。 如果在函数内,但不在cfc内,则处理中止。 更新:我刚刚确认了CF9.0.1下的行为 结果(使用cfexit) Start calling page Called test() Finish calling page Called on requestEnd 结果(使用cfabort) Start calling page Called test() Called on requestEn ... -
在你的查询中你已经指定了dbtype =“query”。 要告诉它查询您之前在某个页面上运行的查询。 在CFC中,查询可能不可用,因为它没有被传入,因此错误。 也许你的意思是在下面使用它并查询你的数据源而不是查询?
SELECT * FROM tbl_name In your query you've specified ... -
Coldfusion this.mappings在cfc - >函数中不起作用(Coldfusion this.mappings does not work in a cfc -> function)[2021-11-14]
我认为你称映射是错误的。 在application.cfc中使用您的定义: this.mappings["plugins"] 然后通过“插件”在其他代码中引用,所以: var aName = new plugins.theCFC() var aName = createObject("component","plugins.theCFC").init()HTH,如果不在调用页面上发布您的代码。 I think you ... -
在cfc中扩展邮件对象(Extending mail object in a cfc)[2023-02-09]
com.adobe.coldfusion.mail中的getter / setter实际上不是函数,而是访问器。 ColdFusion根据组件中的属性自动生成访问器。 属性是继承的,访问者不是! 邮件组件中的访问器除了设置/获取属性的值之外什么都不做。 相当于super.setTo(arguments.recipients); 因此是variables.to = arguments.recipients; 。 this.getTo()的等价物是variables.to等。 注意:对extends="com. ... -
您可以使用$ .get方法执行类似操作,但我通常会执行以下操作: $(document).ready(function() { $("#loadLink").click(function(e) { e.preventDefault(); var recordata = $(this).attr("href").substring(1); //trim '?' char $.ajax({ type: "GET", ...
-
您应该能够在理论上没有任何关于对象名称的上下文的情况下执行它,因为它将从内部执行,并且应该检查其当前目录。 因此,以下应该做你需要的工作 var classPath = ListLast(getMetaData(this).fullname,'.'); return createObject("component", classPath).init(table, this.dsn); 这样,无论目录名称是什么都无关紧要,无论目录结构如何,它都适用于任何扩展该目录的对象,或者用于完整的示例 public f ...
-
这是否打破了cfc的目标取向? 实现cfcs的这种模糊的“对象定位”是一种主观的。 强迫自己陷入“一切都必须是对象”,这会迫使你用CF来做事情,这会造成额外的开销。 我需要小小的妥协来确保应用程序的快速和高效。 不要担心实现“面向对象”的一些不可确定的目标。 制定一个更明确的目标,例如实现cfcs的重用或封装更改。 尝试对对象进行查看并不一定能帮助您实现这些目标,因为每个视图都会有所不同,并且可能无法重复使用。 这是否会导致CFML编译器每次都必须编译视图? Cfms也被编译和缓存。 我有几个大表单组成的标 ...