-1
A
回答
0
import java.io.*;
class Record
{
String name;
String s1;
String s2;
String s3;
String s4;
String s5;
String s6;
public Record(String name, String s1, String s2, String s3, String s4, String s5, String s6){
this.name = name;
this.s1 = s1;
this.s2 = s2;
this.s3 = s3;
this.s4 = s4;
this.s5 = s5;
this.s6 = s6;
}
public static void main(String args[]){
try{
FileInputStream fstream = new FileInputStream("textfile.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
String[] tokens = str.split(" ");
Record record = new Record(tokens[0],tokens[1],tokens[2],tokens[3],tokens[4],tokens[5],tokens[6]);//process record , etc
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
}
6
假设你有
String var = "abc 3.8229 1.0326 1 1 1.1386 1.006";
你可以使用产生一个String.split() String数组。
String[] arr = var.split(" ");
这将产生含有var
每个字的阵列arr
。
3
BufferReader br;
...
String line = br.readLine();
String[] words = line.split(" ");
1
我建议使用扫描仪。
Scanner sc = new Scanner(line);
while(sc.hasNext()){
String word = sc.next(); // Get word
}
在此有利的一面,你也可以使用的
double x = sc.nextDouble();
int i = sc.nextInt();
0
便捷的方法,您可以在您从缓冲区中读取分裂的话:
try {
String line = "abc 3.8229 1.0326 1 1 1.1386 1.006";
List newWordSymbols = Arrays.asList(' ','\n','\r');
StringReader sr = new StringReader(line);
List wordList = new ArrayList();
StringBuilder word = new StringBuilder();
int ch;
while ((ch=sr.read())!=-1) {
char c = (char)ch;
if(newWordSymbols.contains(c)){
wordList.add(word.toString());
word= new StringBuilder();
}else{
word.append(c);
}
}
wordList.add(word.toString());
System.out.println("Word list ::: "+wordList);
} catch (IOException ex) {
ex.printStackTrace();
}
相关问题
- 1. C#字符串数组缓冲区
- 2. 字符串缓冲区 - OutOfMemoryError
- 3. 使用字符数组作为字符串流缓冲区
- 4. 字节缓冲区,字符缓冲区,字符串和字符集
- 5. 循环字符数组缓冲区 - c
- 6. 如何将字节[]数组转换为字符串缓冲区
- 7. 字节缓冲区,字符串
- 8. 字节缓冲区为字符串GWT
- 9. 在协议缓冲区中添加字符串数组
- 10. 缓冲区不会打印字符串
- 11. 预期字符串或缓冲区
- 12. 比较缓冲区与C字符串
- 13. “预期字符串或缓冲区”
- 14. 在缓冲区中查找字符串
- 15. 升压缓冲区麻烦字符串
- 16. 的XMLType字符串缓冲区太小
- 17. 字符串缓冲区声明不足
- 18. 字符串缓冲区需要帮助
- 19. 字符串缓冲区太小
- 20. 字符串缓冲区太小错误
- 21. 包装纸字符串缓冲区
- 22. 从缓冲区中提取字符串
- 23. Node.js缓冲区字符串序列化
- 24. ORA-19011:字符串缓冲区太小
- 25. 预期的字符串或缓冲区
- 26. java套接字缓冲区和字符串
- 27. 读取一个字符并添加到缓冲区字符串java
- 28. 字符串和字符串缓冲区内存概念
- 29. 字符串缓冲区字符串转换异常?
- 30. 字符串连接vs字符串缓冲区在Javascript中
定义一个“字” – 2012-03-27 11:31:44