The first thing would be to not call them up every 30 seconds and just save them in the part of the application that needs the data.

Secondly, put all the bytes into a byte[] and write that in one go.
Also use Buffered I/O Streams.
Thirdly, if you are using Java 7, use NIO.
Fourthly, use File.separator instead of "/" (To others on the forum: Does Java take care of this for you or do you still need to do this?)
Fifthly, You should be checking if the file exists before attempting to read from it. (Don't know how to do this with Java 6)
Multithreading should only be used if you can keep the application running without the files being loaded.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
if(!Files.exists(Paths.get("saves" + File.separator + "...etc"))) getDefaultValues(); BufferedInputStream in = new BufferedInputStream(Files.newInputStream(Paths.get("saves" + File.separator + "...etc"), StandardOpenOption.READ)); BufferedOutputStream out = new BufferedOutputStream(Files.newOutputStream(Paths.get("saves" + File.separator + "...etc"), StandardOpenOption.WRITE, StandardOpenOption.CREATE));
BufferedInputStream in = new BufferedInputStream(new FileInputStream("saves" + File.separator + "...etc")); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("saves" + File.separator + "...etc"));
in.read(id); in.close();
byte[] out = new byte[600] for(int i = 0; i < 300; i++) { out[i*2] = 30; out[i*2+1] = 65; }
out.write(); out.flush(); out.close();
|