我在一个txt文件上写了上千个句子 我的第一个Android应用程序应该从那里取一个 然后把它放在文本View上
我可以将 txt 文件作为一个资源, 或者同样, 尝试把所有的句子 转换成一个数组 。 我不想把我的 txt 放到应用程序中, 而是直接用这些句子直接放入数组 。 我怎么能自动“ 翻译” 上千个句子到一个类似数组的列表?
我在一个txt文件上写了上千个句子 我的第一个Android应用程序应该从那里取一个 然后把它放在文本View上
我可以将 txt 文件作为一个资源, 或者同样, 尝试把所有的句子 转换成一个数组 。 我不想把我的 txt 放到应用程序中, 而是直接用这些句子直接放入数组 。 我怎么能自动“ 翻译” 上千个句子到一个类似数组的列表?
i guess this is what u dont want to do...
//InputStream is = getResources().openRawResource(R.raw.list);
,然后获得一个输入Stream 对象,并跟随代码使用
List<String> content=new ArrayList<String>();
InputStreamReader isr = new InputStreamReader(is);
linereader = new LineNumberReader(isr);
for (int i = 0; i < num; i++) { // num is total no of lines in file
try {
line = linereader.readLine();
content.add(line);
}
catch (IOException e)
{
e.printStackTrace();
}
}// for ends
不要重新发明车轮... 这是一个单行道:
import org.apache.commons.io.IOUtils;
List<String> sentences = (List<String>)IOUtils.readLines(new FileInputStream("filename.txt"));
如果您知道每个项目只有一个时段, 您就可以分开。 如果您不能做到这一点, 但是可以使用新线, 请使用它 。
final String blob = "Quote 1. Quote2. Quote 3 .";
String[] quotes = blob.split( \. );
> ["Quote 1", "Quote2", "Quote 3 "];
OR
final String blob = "Quote 1.
Quote 2 longer.";
String[] quotes = blob.split("
");
> ["Quote 1.", "Quote 2 longer."]
听上去您想将文本文件放入资源文件夹, 然后用缓冲 Reader 读取它 。
根据文本文件的内容,您可以逐行阅读文本行并将其添加到一个矩阵中,或者将整个文件作为字符串阅读,然后使用.split (), 这将返回一个字符串, 供您使用 。
Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i < 10000; i++) { String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...
If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...
I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...