Skip to content

Instantly share code, notes, and snippets.

@aerodame
Created March 10, 2025 19:49
Show Gist options
  • Save aerodame/2259f0548fbd62d3c5609338dc29637e to your computer and use it in GitHub Desktop.
Save aerodame/2259f0548fbd62d3c5609338dc29637e to your computer and use it in GitHub Desktop.
private static void createFileWithPhrase(String filename, String phrase) {
File file = new File(filename);
try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw")) {
randomAccessFile.write(phrase.getBytes()); // Write the string as bytes.
System.out.println("File " + filename + " created with the phrase: \"" + phrase + "\"");
} catch (IOException e) {
System.err.println("Error creating file: " + e.getMessage());
}
}
static class FileRegionTask implements Runnable {
private final String filename;
private final long startPosition;
private final long regionSize;
private final String threadName;
public FileRegionTask(String filename, long startPosition, long regionSize, String threadName) {
this.filename = filename;
this.startPosition = startPosition;
this.regionSize = regionSize;
this.threadName = threadName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment