I want to convert a string that I get from a file, to an arraylist. I tried it this way, but it doesn't work:
import java.io.*; import java.util.*; public class Data { static File file = DataSaver.file; static List<String> data = new ArrayList<String>(512); public static void a() throws Exception { FileInputStream fis = new FileInputStream(file); DataInputStream dis = new DataInputStream(fis); BufferedReader reader = new BufferedReader(new InputStreamReader(dis)); if(!file.exists()) { throw new IOException("Datafile not found."); } else { String[] string = reader.readLine().split("$"); for(int i = 0; i < string.length; i++) { data.add(string[i]); } } dis.close(); System.out.println(data.toString()); //for debugging purposes. } } Ouput: [$testdata1$testdata2$]
Wanted output: [testdata1, testdata2]
File content: $testdata1$testdata2$
Can someone help me?
String'string'?stringis an alias forString). Furthermore, it doesn't really describe what's contained in the variable.