099988899,valid,2012-09-10 16:02
099988895,valid,2012-09-10 16:02
099988896,valid,2012-09-10 16:02
099988893,valid,2012-09-10 16:02
099988892,valid,2012-09-10 16:02
怎么取前面那段数字出来?
注意下,这个是从txt中读取出来的,或者有什么方法读取的时候只得到前面那段数字。
弄出来了,突然想到的。。既然是一个分了段的字符串,那么我先用split("\n")获得数组,然后循环得到 如:str[i].split(",")[0],就能得到数字了。。
######灵感突然来了吧。。。所以多上OS没错的。。哇哈哈。######好多种方法,正则或者split######split怎分,这个是个整体啊,######
String[] str="099988899,valid,2012-09-10 16:02".split(","); str[0];//就是099988899
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; public class Test { public static void main(String[] args) throws Exception { File file = new File("D:" + File.separator + "str.txt"); BufferedReader fr = new BufferedReader(new FileReader(file)); String temp = null; while ((temp = fr.readLine()) != null) { System.out.println(temp.split(",")[0]); } } }
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class Test {
public static void main(String[] args) throws Exception {
File file = new File("D:" + File.separator + "str.txt");
BufferedReader fr = new BufferedReader(new FileReader(file));
String temp = null;
while ((temp = fr.readLine()) != null) {
System.out.println(temp.split(",")[0]);
}
}
}
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; public class Test { public static void main(String[] args) throws Exception { File file = new File("D:" + File.separator + "str.txt"); BufferedReader fr = new BufferedReader(new FileReader(file)); String temp = null; while ((temp = fr.readLine()) != null) { System.out.println(temp.split(",")[0]); } } }
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class Test {
public static void main(String[] args) throws Exception {
File file = new File("D:" + File.separator + "str.txt");
BufferedReader fr = new BufferedReader(new FileReader(file));
String temp = null;
while ((temp = fr.readLine()) != null) {
System.out.println(temp.split(",")[0]);
}
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。