Apache库到标准Java

Apache库到标准Java,java,eclipse,apache,Java,Eclipse,Apache,我有个问题。我编写了这段代码,从txt文件中读取一个字符串,并使用第一个方法导出一个int,而第二个方法则导出一个特定的字符串。这个方法已经在运行,但是我已经使用了apache库,现在我想在Java标准库中重写它。我试过这个,但我遇到了问题。有人能帮我吗?多谢各位 package ausiliare; import java.io.File; import java.io.IOException; import org.apache.commons.io.*; public class Re

我有个问题。我编写了这段代码,从txt文件中读取一个字符串,并使用第一个方法导出一个int,而第二个方法则导出一个特定的字符串。这个方法已经在运行,但是我已经使用了apache库,现在我想在Java标准库中重写它。我试过这个,但我遇到了问题。有人能帮我吗?多谢各位

package ausiliare;

import java.io.File;
import java.io.IOException;
import org.apache.commons.io.*;

public class Read {
public static int getInt() throws IOException {

    String content = null;
    File folder = new File("C:\\Solution.txt");

    content = FileUtils.readFileToString(folder) + "\n";

    int outside = Integer.parseInt(content.substring(0,
            content.indexOf("[")).trim());
    return outside;
}

public static String getString() throws IOException {
    String content = null;
    File folder = new File("C:\\Solution.txt");
    content = FileUtils.readFileToString(folder) + "\n";
    String remainingString = content.substring(content.indexOf(" ["),
            content.lastIndexOf("]") + 1);
    // System.out.println(remainingString);
    return remainingString;

}

public static String[] arg() throws IOException {
    String[] strArray = getString().split(" ");
    // System.out.println(Arrays.toString(strArray));
    return strArray;

}
}

Ps:输入文件为txt,例如:

50 [8,24,-22] [-8,34,12] [19,14,47] [-49,32,44] [-41,16,-6] [-49,-11,43]
其中,第一种方法提取int 50,第二种提取方法提取剩余的int 50

content = new String(Files.readAllBytes(folder.toPath()),
       StandardCharsets.UTF_8);
缺少的部分是课堂知识

还有一个readAllLines列表


字符集参数是可选的,默认为当前操作系统的编码-对其他计算机来说不是很方便。

欢迎使用StackOverflow,到目前为止您尝试了什么?所以,您使用的唯一方法是FileUtils.readFileToString,对吗?看一看:嗨,我试着在标准java库下运行。但是我在提取子字符串方面没有问题。我无法阅读与apache相同的内容。谢谢