try {
File file = new File(“filename”);
FileChannel channel = new RandomAccessFile(file, “rw”).getChannel();FileLock lock = channel.lock();
try {
lock = channel.tryLock();
} catch (OverlappingFileLockException e) {
// File is already locked in this thread or virtual machine
}lock.release();
channel.close();
}catch(Exception e){
}
날짜: 2008 6월 13
Convert interchangeably between a ByteBuffer and a byte array
1. create a ByteBuffer from a byte array
byte[] bytes = new byte[10];
ByteBuffer buffer = ByteBuffer.wrap(bytes);
2. retrieve bytes between the position and limit
bytes = new byte[buffer.remaining()];
buffer.get(bytes, 0, bytes.length);
buffer.clear();
3. retrieve all bytes in the buffer
bytes = new byte[buffer.capacity()];
buffer.get(bytes, 0, bytes.length);
debugging을 위한 class line 보기
아래와 같이 처리합니다. ^^
System.out.println((new Throwable()).getStackTrace()[0].getLineNumber());