java在字符串开头添加字符串_如何在Java中提取字符串的开头

我有一个超过20,000行的文本文件,我需要从中提取特定行。该程序的输出完全是空白文件。

txt文件中有20,000行,该ISDN行不断重复很多时间,每个时间都有不同的值。我的文本文件包含以下数据。

RecordType=0(MOC)

sequenceNumber=456456456

callingIMSI=73454353911

callingIMEI=85346344

callingNumber

AddInd=H45345'1

NumPlan=H34634'2

ISDN=94634564366 // Need to extract this "ISDN" line only

public String readTextFile(String fileName) {

String returnValue = "";

FileReader file = null;

String line = "";

String line2 = "";

try {

file = new FileReader(fileName);

BufferedReader reader = new BufferedReader(file);

while ((line = reader.readLine()) != null) {

// extract logic starts here

if (line.startsWith("ISDN") == true) {

System.out.println("hello");

returnValue += line + "\n";

}

}

} catch (FileNotFoundException e) {

throw new RuntimeException("File not found");

} finally {

if (file != null) {

try {

file.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

return returnValue;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值