本文整理汇总了Java中java.io.RandomAccessFile.writeChars方法的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessFile.writeChars方法的具体用法?Java RandomAccessFile.writeChars怎么用?Java RandomAccessFile.writeChars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.RandomAccessFile
的用法示例。
在下文中一共展示了RandomAccessFile.writeChars方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRandomFile
import java.io.RandomAccessFile; //导入方法依赖的package包/类
private static File createRandomFile(String uuid, Long size) throws IOException {
File file = new File("/tmp/" + uuid + ".txt");
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
randomAccessFile.writeChars(uuid);
if (size != null) {
randomAccessFile.setLength(size);
}
randomAccessFile.close();
return file;
}
示例2: createRandomFile
import java.io.RandomAccessFile; //导入方法依赖的package包/类
private static Path createRandomFile(long size) throws IOException {
Path path = Paths.get("/tmp/" + UUID.randomUUID().toString() + ".txt");
RandomAccessFile file = new RandomAccessFile(path.toString(), "rw");
file.writeChars("test content\n");
file.setLength(size);
file.close();
return path;
}
示例3: writeMsgToFile
import java.io.RandomAccessFile; //导入方法依赖的package包/类
private void writeMsgToFile(File targetFile, String msg) {
FileNotFoundException e;
Throwable th;
IOException e2;
try {
if (!targetFile.exists()) {
targetFile.createNewFile();
}
if (targetFile != null && targetFile.exists() && !TextUtils.isEmpty(msg)) {
RandomAccessFile raf = null;
try {
RandomAccessFile raf2 = new RandomAccessFile(targetFile, "rw");
try {
raf2.seek(targetFile.length());
raf2.writeChars("\n<----" + new Date().toString() + "---->\n");
raf2.writeChars(msg);
if (raf2 != null) {
try {
raf2.close();
} catch (IOException e3) {
raf = raf2;
return;
}
}
raf = raf2;
} catch (FileNotFoundException e4) {
e = e4;
raf = raf2;
try {
e.printStackTrace();
if (raf != null) {
try {
raf.close();
} catch (IOException e5) {
}
}
} catch (Throwable th2) {
th = th2;
if (raf != null) {
try {
raf.close();
} catch (IOException e6) {
}
}
throw th;
}
} catch (IOException e7) {
e2 = e7;
raf = raf2;
e2.printStackTrace();
if (raf != null) {
try {
raf.close();
} catch (IOException e8) {
}
}
} catch (Throwable th3) {
th = th3;
raf = raf2;
if (raf != null) {
raf.close();
}
throw th;
}
} catch (FileNotFoundException e9) {
e = e9;
e.printStackTrace();
if (raf != null) {
raf.close();
}
} catch (IOException e10) {
e2 = e10;
e2.printStackTrace();
if (raf != null) {
raf.close();
}
}
}
} catch (IOException e11) {
}
}