
如何用java提取txt文件中的数字并保存到另外一个数组中,txt文件中内容为[15,4,7,9,34]
xt文件中内容为[15,4,7,9,34]关键是既有中括号又有逗号目的是提取出15,4,7,9,34并存放在另外一个数组中...
xt文件中内容为[15,4,7,9,34] 关键是既有中括号 又有逗号 目的是提取出15,4,7,9,34并存放在另外一个数组中
展开
2个回答
展开全部
import java.io.File;
import java.io.FileReader;
import java.util.regex.Pattern;
public class ReadFile {
public static void main(String[] args) throws Exception {
File f = new File("d:" + File.separator + "number.txt") ;
FileReader fr = new FileReader(f) ;
char c[] = new char[1024] ;
int temp = 0 ;
int len = 0 ;
while((temp=fr.read())!=-1){
c[len] = (char)temp ;
len++ ;
}
fr.close() ;
String str = new String(c,0,len) ;
String pat = "\\D+" ; // 指定好正则表达式
Pattern p = Pattern.compile(pat) ; // 实例化Pattern类
String s[] = p.split(str) ; // 执行拆分操作
for(String num : s){
System.out.print(num + " ");
}
}
}
import java.io.FileReader;
import java.util.regex.Pattern;
public class ReadFile {
public static void main(String[] args) throws Exception {
File f = new File("d:" + File.separator + "number.txt") ;
FileReader fr = new FileReader(f) ;
char c[] = new char[1024] ;
int temp = 0 ;
int len = 0 ;
while((temp=fr.read())!=-1){
c[len] = (char)temp ;
len++ ;
}
fr.close() ;
String str = new String(c,0,len) ;
String pat = "\\D+" ; // 指定好正则表达式
Pattern p = Pattern.compile(pat) ; // 实例化Pattern类
String s[] = p.split(str) ; // 执行拆分操作
for(String num : s){
System.out.print(num + " ");
}
}
}
2016-01-12
展开全部
”晴天雾去“是”好天气来了,好日子来了。“的意思
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询