I have a file whose size is about 300mb. I want to read the contents line by line and then add it into ArrayList. So I have made an object of array list a1 , then reading the file using BufferedReader , after that when I add the lines from file into ArrayList it gives an error Exception in thread "main" java.lang.OutOfMemoryError: Java heap space.
Please tell me what should be the solution for this.
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
FileReader file = new FileReader(
"/home/dmdd/Desktop/AsiaData/RawData/AllupperairVcomponent.txt");
ArrayList a1 = new ArrayList();
BufferedReader br = new BufferedReader(file);
String line = "";
while ((line = br.readLine()) != null) {
a1.add(line);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}