List of usage examples for java.io RandomAccessFile seek
public void seek(long pos) throws IOException
From source file:org.telegram.ui.PassportActivity.java
private EncryptionResult createSecureDocument(String path) { File file = new File(path); int length = (int) file.length(); byte[] b = new byte[length]; RandomAccessFile f = null; try {/* www . j a v a2 s.co m*/ f = new RandomAccessFile(path, "rws"); f.readFully(b); } catch (Exception ignore) { } EncryptionResult result = encryptData(b); try { f.seek(0); f.write(result.encryptedData); f.close(); } catch (Exception ignore) { } return result; }
From source file:com.peterbochs.PeterBochsDebugger.java
public String tail2(File file, int lines) { try {/* w ww. j a v a 2 s . c om*/ RandomAccessFile fileHandler = new RandomAccessFile(file, "r"); long fileLength = file.length() - 1; StringBuilder sb = new StringBuilder(); int line = 0; for (long filePointer = fileLength; filePointer != -1; filePointer--) { fileHandler.seek(filePointer); int readByte = fileHandler.readByte(); if (readByte == 0xA) { line = line + 1; if (line == lines) { if (filePointer == fileLength) { continue; } else { break; } } } sb.append((char) readByte); } sb.deleteCharAt(sb.length() - 1); String lastLine = sb.reverse().toString(); return lastLine; } catch (Exception e) { return null; } }
From source file:com.codename1.impl.android.AndroidImplementation.java
/** * @inheritDoc//from w w w . j ava 2s . c o m */ public OutputStream openOutputStream(Object connection, int offset) throws IOException { String con = (String) connection; con = removeFilePrefix(con); RandomAccessFile rf = new RandomAccessFile(con, "rw"); rf.seek(offset); FileOutputStream fc = new FileOutputStream(rf.getFD()); BufferedOutputStream o = new BufferedOutputStream(fc, con); o.setConnection(rf); return o; }