My input.txt file is :
President=obama
Vice President=Biden
Head of State=Kerry
package Test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.StringJoiner;
public class Stringbuilder {
public static void main(String[] args) throws FileNotFoundException, IOException {
{
try (BufferedReader br = new BufferedReader(new FileReader("input.txt"))) {
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
String[] results = sCurrentLine.split("");
String word = sCurrentLine;
String Sym = "=";
for (int i = 0; i < sCurrentLine.length(); i++) {
if (word.contains(Sym)) {
// System.out.println(results[1]);
for (int j = 0; j < sCurrentLine.length(); j++) {
String content = results[j];
System.out.println(content);
File file = new File("output.txt");
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
System.out.println("Done");
}
}
}
}
}
}
}
}?
public static void main(String[] args) throws IOException {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(new File("output.txt").getAbsoluteFile()))) {
for (String sCurrentLine: Files.readAllLines(Paths.get("input.txt"))) {
String[] splitted = sCurrentLine.split("=");
if (splitted.length > 1) {
for (int i = 1; i < splitted.length; i++) {
bw.write(splitted[i].split("\\s+")[0] + "\n");
}
}
}
}
}
「正しく動作していません。」と精緻化していますか?入力/出力/スタックトレースを提供する。詳細が不足しているため投票を閉じる –
入力ファイルの例と出力を追加してください。 – chenchuk
入力ファイルの詳細を追加しました。 – sainid