一个Java问题

来源:百度知道 编辑:UC知道 时间:2024/05/10 19:05:24
我将一个文本文件读入,由于文件中都是一些词组,所以我想将词组逐个读入,并且将他们逐个存入一个字符串,如何办到
各个词组用空格分开

将词组用特定的符号分开,不然不好辨认。

要不就用搜索引擎!

public static void main(String[] args) {
String s = null;
File f = new File("d://1.txt");
FileReader fr = null;
try {
fr = new FileReader(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader br = new BufferedReader(fr);
try {
s = br.readLine();

System.out.println(s.split(" "));
} catch (IOException e) {
e.printStackTrace();
}
String[] ss = s.split(" ");

}

路径 你自己定,得到的结果你可以自己处理了!!

有不懂的再问!

给你个用空格分割的小例子:
public class Test{
public static void main(String[] args){
String s="afe bfe cfe d23 efe ffe";
String st[]=new String[s.length()];
st=s.split(" ");//用空格分格
for(String ss:st)
System.out.println(ss);
}
}
同样的道理,把你的内容读入到一个Str