java读取TXT文件,然后截取字符串
TXT文件内容是‘1.jpg’,‘1’,‘2’,‘3’;‘2.jpg’,‘3’,‘4’,‘5’;‘3.jpg’,‘44’,‘55’,‘66‘;需求是怎么截取后获得3个数组...
TXT文件内容是‘1.jpg’,‘1’,‘2’,‘3’;‘2.jpg’,‘3’,‘4’,‘5’;‘3.jpg’,‘44’,‘55’,‘66‘;
需求是怎么截取后获得3个数组分别是[1,2,3] [3,4,5] [44,55,66] 能远程的加我企鹅510 1437 解决了再追50分 展开
需求是怎么截取后获得3个数组分别是[1,2,3] [3,4,5] [44,55,66] 能远程的加我企鹅510 1437 解决了再追50分 展开
2个回答
展开全部
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
public class $ {
public static void main(String[] args) {
try {
Scanner in = new Scanner(new File("D:/a.sql"));
while (in.hasNextLine()) {
String str = in.nextLine();
String[] arr = str.split(",");
Float[] result = new Float[arr.length - 1];
for (int i = 0; i < result.length; i++) {
result[i] = Float.parseFloat(trim(arr[i + 1]));
}
System.out.println(Arrays.toString(result));
}
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
private static String trim(String str) {
str = str.replaceAll("'", "");
str = str.replaceAll(";", "");
return str;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询