So i have a working network file transfer program now (if you want to see some of the code look at my other 'article').
But now that im trying larger files, im running into a problem where i run out of memory (which is understandable when the array is
1 000 000+ in length). I cant figure out how to split a file up into smaller arrays. At the moment i just load the file into one big array:
byte[] fileArray;
JFileChooser chooser = new JFileChooser();
chooser.showDialog(this, "Send");
File file = chooser.getSelectedFile();
Path path = Paths.get(file.getAbsolutePath());
try {
fileArray = Files.readAllBytes(path);
} catch (IOException e1) {
e1.printStackTrace();
fileArray = null;
}
I havn't been able to find another way to load the file than the Files.readAllBytes(Path); which doesnt allow me to split it up.
Help is, as always, appreciated!
EDIT: I've found a few solutions suggesting using third party libraries, i'd really prefer it if i could stay with the java framework.