Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
29
Task/Fixed-length-records/Java/fixed-length-records-1.java
Normal file
29
Task/Fixed-length-records/Java/fixed-length-records-1.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import module java.base;
|
||||
|
||||
public final class FixedLengthRecords {
|
||||
|
||||
public static void main() throws IOException {
|
||||
try ( FileChannel reader = FileChannel.open(Path.of("./infile.dat"), StandardOpenOption.READ);
|
||||
FileChannel writer = FileChannel.open(Path.of("./outfile.dat"), StandardOpenOption.CREATE,
|
||||
StandardOpenOption.WRITE) ) {
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
|
||||
|
||||
while ( reader.read(buffer) != END_OF_FILE ) {
|
||||
for ( int i = 0, j = BUFFER_SIZE - 1; i < j; j--, i++ ) {
|
||||
final byte temp = buffer.get(i);
|
||||
buffer.put(i, buffer.get(j));
|
||||
buffer.put(j, temp);
|
||||
}
|
||||
|
||||
buffer.flip();
|
||||
writer.write(buffer);
|
||||
buffer.flip();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final int BUFFER_SIZE = 80;
|
||||
private static final int END_OF_FILE = -1;
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue