I'm trying to write a file with some amount of data using this:
public static <T extends SomeClass> void writeFile(String buffer, Class<T> clazz, int fileNumber) { String fileType = ".txt"; File file = new File(clazz.getName()+fileNumber+fileType); PrintWriter printWriter = null; try { FileWriter writer = new FileWriter(file); printWriter = new PrintWriter(writer); printWriter.print(buffer);//error occurs here printWriter.flush(); printWriter.close(); System.out.println("created file: "+file.getName()); } catch (IOException e) { e.printStackTrace(); } finally{ if(printWriter!=null){ printWriter.flush(); printWriter.close(); } } System.out.println("Done!"); } The buffer string contains +-6mb of data, and when i run the code i get a java.lang.OutOfMemoryError exactly in buffer.