本文整理了Java中java.io.RandomAccessFile.writeBytes
方法的一些代码示例,展示了RandomAccessFile.writeBytes
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RandomAccessFile.writeBytes
方法的具体详情如下:
包路径:java.io.RandomAccessFile
类名称:RandomAccessFile
方法名:writeBytes
[英]Writes the low order 8-bit bytes from a string to this file, starting at the current file pointer.
[中]从当前文件指针开始,将字符串中的低位8位字节写入该文件。
代码示例来源:origin: cymcsg/UltimateAndroid
/**
* Append file using RandomAccessFile
*
* @param fileName
* @param content
*/
public static void WriteStreamAppendByRandomAccessFile(String fileName, String content) throws IOException {
try {
RandomAccessFile randomFile = new RandomAccessFile(fileName, "rw");
long fileLength = randomFile.length();
// Write point to the end of file.
randomFile.seek(fileLength);
randomFile.writeBytes(content);
randomFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
代码示例来源:origin: apache/activemq
@Override
public void writeBytes(String s) throws IOException {
try {
getRaf().writeBytes(s);
} catch (IOException ioe) {
handleException();
throw ioe;
}
}
代码示例来源:origin: apache/ignite
ra.writeBytes(String.valueOf(port));
代码示例来源:origin: jeremylong/DependencyCheck
file = new RandomAccessFile(lockFile, "rw");
lock = file.getChannel().lock();
file.writeBytes(magic);
file.getChannel().force(true);
Thread.sleep(20);
代码示例来源:origin: apache/ignite
/**
* @throws Exception If failed.
*/
@Test
public void testReadLineFromBinaryFile() throws Exception {
File file = new File(FILE_PATH);
file.deleteOnExit();
RandomAccessFile raf = new RandomAccessFile(file, "rw");
byte[] b = new byte[100];
Arrays.fill(b, (byte)10);
raf.write(b);
raf.writeBytes("swap-spaces/space1/b53b3a3d6ab90ce0268229151c9bde11|" +
"b53b3a3d6ab90ce0268229151c9bde11|1315392441288" + U.nl());
raf.writeBytes("swap-spaces/space1/b53b3a3d6ab90ce0268229151c9bde11|" +
"b53b3a3d6ab90ce0268229151c9bde11|1315392441288" + U.nl());
raf.write(b);
raf.writeBytes("test" + U.nl());
raf.getFD().sync();
raf.seek(0);
while (raf.getFilePointer() < raf.length()) {
String s = raf.readLine();
X.println("String: " + s + ";");
X.println("String length: " + s.length());
X.println("File pointer: " + raf.getFilePointer());
}
}
代码示例来源:origin: stackoverflow.com
randomAccessWriter.writeBytes("RIFF");
randomAccessWriter.writeInt(0); // Final file size not known yet, write 0
randomAccessWriter.writeBytes("WAVE");
randomAccessWriter.writeBytes("fmt ");
randomAccessWriter.writeInt(Integer.reverseBytes(16)); // Sub-chunk size, 16 for PCM
randomAccessWriter.writeShort(Short.reverseBytes((short) 1)); // AudioFormat, 1 for PCM
randomAccessWriter.writeShort(Short.reverseBytes((short)(nChannels*bSamples/8))); // Block align, NumberOfChannels*BitsPerSample/8
randomAccessWriter.writeBytes("data");
randomAccessWriter.writeInt(0); // Data chunk size not known yet, write 0
代码示例来源:origin: i2p/i2p.i2p
public void writeBytes(String s) throws IOException { delegate.writeBytes(s); }
public void writeChars(String s) throws IOException { delegate.writeChars(s); }
代码示例来源:origin: apache/hive
LOG.info("corrupting " + raf + " at offset " + corruptOffset);
raf.seek(corruptOffset);
raf.writeBytes("junkjunkjunkjunkjunkjunkjunkjunk");
raf.close();
代码示例来源:origin: 0opslab/opslabJutil
/**
* 将字符串写入到文件中
*/
public final static boolean write(File file, String str) {
try (
RandomAccessFile randomFile = new RandomAccessFile(file, "rw")
) {
randomFile.writeBytes(str);
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
代码示例来源:origin: 0opslab/opslabJutil
/**
* 写文件
*
* @param file 需要处理的函数
* @param str 添加的子字符串
* @return 是否成功
*/
public static boolean write(File file, String str) {
try (
RandomAccessFile randomFile = new RandomAccessFile(file, "rw")
) {
randomFile.writeBytes(str);
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
代码示例来源:origin: 0opslab/opslabJutil
/**
* 将字符串以追加的方式写入到文件中
*/
public final static boolean writeAppend(File file, String str) {
try (
RandomAccessFile randomFile = new RandomAccessFile(file, "rw")
) {
long fileLength = randomFile.length();
randomFile.seek(fileLength);
randomFile.writeBytes(str);
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
代码示例来源:origin: 0opslab/opslabJutil
/**
* 在文件末尾追加一行
*
* @param file 需要处理的函数
* @param str 添加的子字符串
* @return 是否成功
*/
public final static boolean appendLine(File file, String str) {
try (
RandomAccessFile randomFile = new RandomAccessFile(file, "rw")
) {
long fileLength = randomFile.length();
randomFile.seek(fileLength);
randomFile.writeBytes(SysUtil.FILE_SEPARATOR + str);
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
代码示例来源:origin: 0opslab/opslabJutil
/**
* 写文件
*
* @param file 需要处理的函数
* @param str 添加的子字符串
* @return 是否成功
*/
public static boolean addWrite(File file, String str) {
try (
RandomAccessFile randomFile = new RandomAccessFile(file, "rw")
) {
long fileLength = randomFile.length();
randomFile.seek(fileLength);
randomFile.writeBytes(str);
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
代码示例来源:origin: apache/jackrabbit-oak
@Override
public void writeLine(String line) throws IOException {
journalFile.writeBytes(line + "\n");
journalFile.getChannel().force(false);
}
代码示例来源:origin: de.dfki.mary/marytts-builder
private void setWikipediaFileDone(String fileName, String fileDone) {
RandomAccessFile out = null;
try {
out = new RandomAccessFile(fileName, "rw");
out.seek(out.length());
out.writeBytes(fileDone + "\n");
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) throws Exception {
RandomAccessFile file = new RandomAccessFile("test.txt", "rws");
byte[] text = new byte[(int) file.length()];
file.readFully(text);
file.seek(0);
file.writeBytes("Prepend 8");
file.write(text);
file.close();
System.out.println("Done");
}
代码示例来源:origin: org.jvnet.hudson.hadoop/hadoop-core
protected void writeCorruptedData(RandomAccessFile file) throws IOException {
final String messageForPreUpgradeVersion =
"\nThis file is INTENTIONALLY CORRUPTED so that versions\n"
+ "of Hadoop prior to 0.13 (which are incompatible\n"
+ "with this directory layout) will fail to start.\n";
file.seek(0);
file.writeInt(FSConstants.LAYOUT_VERSION);
org.apache.hadoop.io.UTF8.writeString(file, "");
file.writeBytes(messageForPreUpgradeVersion);
file.getFD().sync();
}
}
代码示例来源:origin: org.apache.activemq/activemq-kahadb-store
@Override
public void writeBytes(String s) throws IOException {
try {
getRaf().writeBytes(s);
} catch (IOException ioe) {
handleException();
throw ioe;
}
}
代码示例来源:origin: org.apache.activemq/activemq-all
@Override
public void writeBytes(String s) throws IOException {
try {
getRaf().writeBytes(s);
} catch (IOException ioe) {
handleException();
throw ioe;
}
}
代码示例来源:origin: octo-online/reactive-audit
@Test(expected = FileReactiveAuditException.class)
public void writeBytes()
throws IOException
{
ReactiveAudit.off.commit();
try (RandomAccessFile rw = newRandomAccessFile())
{
TestTools.strict.commit();
rw.writeBytes("");
}
}
内容来源于网络,如有侵权,请联系作者删除!