在java中选择以整数值开头的文本文件中的行 我使用pdfbox for java从pdf中抓取了一个文件,输出如下:

在java中选择以整数值开头的文本文件中的行 我使用pdfbox for java从pdf中抓取了一个文件,输出如下:,java,pdf,text,file-io,pdfbox,Java,Pdf,Text,File Io,Pdfbox,该列表继续重复每页的前6行[150页]。我需要做的是在java中选择以整数值开头的行,并使用以整数值开头的列表创建一个新文件。您可以将输出拆分为单独的行,然后对每行使用.startsWith(“[0-9]”) 例如: // let's presume that you've loaded the lines into "List<String> lines".. // empty ArrayList for storing the selected lines List<St

该列表继续重复每页的前6行[150页]。我需要做的是在java中选择以整数值开头的行,并使用以整数值开头的列表创建一个新文件。

您可以将输出拆分为单独的行,然后对每行使用.startsWith(“[0-9]”)

例如:

// let's presume that you've loaded the lines into "List<String> lines"..

// empty ArrayList for storing the selected lines
List<String> linesToWrite = new ArrayList<>();

for(String line : lines)
{
    if(line.startsWith("[0-9]"))
    {
        linesToWrite.add(line);
    }
}
// and now write it to the other file
//假设您已将行加载到“列表行”中。。
//用于存储选定行的空ArrayList
List linesToWrite=new ArrayList();
用于(字符串行:行)
{
if(第行开始,以“[0-9]”开头)
{
linesToWrite.add(行);
}
}
//现在将其写入另一个文件

你还没有尝试过什么?!我试图删除字符串,但是页码从1到150时出现问题,我也需要保留这些数字。您尝试过的代码在哪里?StartWith(“[0-9]”)不起作用,但它可以处理字符值。?尝试使用StartWith(“[\d]”)基本上是一样的第二个文件中有什么输出?您是否尝试过调试它并观察“lines”和“linesToWrite”中的内容?问题在于范围[0-9],如果将单个整数表示为line.startsWith(“1”);则输出是正常的;[\d]工作不太好如果我理解正确的话,您需要检查的所有内容都是行的第一个字符。。如果它是一个数字,它应该返回true。。“1asdqwe”和“12asd23asd”均应视为以数字开头的行。。
// let's presume that you've loaded the lines into "List<String> lines"..

// empty ArrayList for storing the selected lines
List<String> linesToWrite = new ArrayList<>();

for(String line : lines)
{
    if(line.startsWith("[0-9]"))
    {
        linesToWrite.add(line);
    }
}
// and now write it to the other file