使用 BufferedInputStream 和 Java 中的 RTL 字符将文本文件逐行解析为数组
伙计们,我需要明白一些事情: \n 出现在新行的开头正确吗? 如果是这样,我试图解析一个包含 RTL 字符的文件,并且它们位于行的开头,因此:
- xxx xxxx, ABC DEFG, 1, 11, 111, 786
- xxx xxxx, ABC DEFG, 1, 11 、111、786
- 等...
在解析 txt 文件(来自资产的 android)时,我不断从连接到的下一行中获取第一个单词上一行的整数。 我已经尝试了一切,但没有运气。
这是一个代码片段:
InputStream is;
try {
is = new BufferedInputStream(getAssets().open(fileName));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
InputStream is = new BufferedInputStream(getAssets().open(fileName));
byte[] c = new byte[128];
byte[] d = null;
int readChars = 0;
int lineNumber = 0;
String line;
String[] paramLineArray = null;
int k;
while ((readChars = is.read(c)) != -1) {
for (int i = 0; i < readChars; i++) {
if (c[i] == '\n') {
lineNumber++;
line = new String(c);
k = 0;
StringTokenizer st = new StringTokenizer(line,",");
paramLineArray = new String[st.countTokens()];
while (st.hasMoreTokens()) {
// get next token and store it in the Line
paramLineArray[k] = st.nextToken();
k++;
}
}
}
publishProgress(((int) (1 / (float) lineNumber) * 100));
populateTables(paramLineArray, tblName, tblElements);
}
我想要实现的是:
非常快地解析文本文件 逐行插入一个数组,然后插入到数据库中......
有什么想法吗???
非常感谢您的帮助,因为我已经这样做了好几天了(失去了我的头发:-()...
目前我有与InputStreamReader一起使用的代码,但它非常慢!!!!!
谢谢。JadeYe
。
Guys I need to understand something:
the \n comes at the begining of a new line currect?
If so, I am trying to parse a file that has RTL characters in it and they are at the begining of a line, so:
- xxx xxxx, ABC DEFG, 1, 11, 111, 786
- xxx xxxx, ABC DEFG, 1, 11, 111, 786
- etc...
when parsing the txt file (android from assets) I keep getting the first word from the next line concatenated to the Integer from the previous line.
I have tried everything but with no luck.
Here is a code snippet:
InputStream is;
try {
is = new BufferedInputStream(getAssets().open(fileName));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
InputStream is = new BufferedInputStream(getAssets().open(fileName));
byte[] c = new byte[128];
byte[] d = null;
int readChars = 0;
int lineNumber = 0;
String line;
String[] paramLineArray = null;
int k;
while ((readChars = is.read(c)) != -1) {
for (int i = 0; i < readChars; i++) {
if (c[i] == '\n') {
lineNumber++;
line = new String(c);
k = 0;
StringTokenizer st = new StringTokenizer(line,",");
paramLineArray = new String[st.countTokens()];
while (st.hasMoreTokens()) {
// get next token and store it in the Line
paramLineArray[k] = st.nextToken();
k++;
}
}
}
publishProgress(((int) (1 / (float) lineNumber) * 100));
populateTables(paramLineArray, tblName, tblElements);
}
What I am trying to achieve is this:
Parse the text file really fast
Line by line into an array that is the inserted into a DB...
Any ideas???
Help is much appreciated as I've been at it for days now (loosing my hair :-()...
Currently I have code working with InputStreamReader but it is very slow!!!!!
Thank you.
JadeYe.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用:
Use: