文字列を ArrayList に分割したいと思います。例:
文字列 = 「質問への回答を希望しますか」の結果は金額 3 になります: Wou -> arraylist、ld -> arraylist、you -> arraylist、...
金額は事前定義された変数です。
これまでのところ:
public static void analyze(File file) {
ArrayList<String> splittedText = new ArrayList<String>();
StringBuffer buf = new StringBuffer();
if (file.exists()) {
try {
FileInputStream fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis,
Charset.forName("UTF-8"));
BufferedReader reader = new BufferedReader(isr);
String line = "";
while ((line = reader.readLine()) != null) {
buf.append(line + "\n");
splittedText.add(line + "\n");
}
reader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
String wholeString = buf.toString();
wholeString.substring(0, 2); //here comes the string from an txt file
}