I am trying to write the contents of an arraylist to a text file. I am partially able to do this with my newbie coding skills, however at the moment it only writes the first line out of 48 lines to the text file.
I would assume that this might be due to the fact that i do not have a loop anywhere in my code however, i am not entirely sure whether id need a while loop, or for loop and where exactly i would need to put it? Could this perhaps be also due to my readFile
method using String(readAllBytes(get(filename)))
as opposed to reading in line by line?
public static void main(String... p) throws IOException {
List<SensorInfo> readings = new ArrayList<>();
String filedata = readFile("client-temp.txt");
SensorInfo info = new SensorInfo(filedata);
readings.add(info);
String data = createStringFromInfo(readings);
System.out.println("Lines: " + readings.size());
writeFile("datastore.txt", data);
}
}
writeFile
public static void writeFile(String filename, String content)
{
try
{
Files.write(get(filename), content.getBytes());
}
catch (IOException e)
{
System.out.println("Error wiring file: " + e);
}
}
createStringFromInfo
public static String createStringFromInfo(List<SensorInfo> infoList)
{
String data = "";
for (SensorInfo info : infoList)
{
data += info.asData();
}
return data;
}
SensorInfo http://pastebin.com/9DDDGzwV