Java Code Examples for java.io.RandomAccessFile#writeChar()

The following examples show how to use java.io.RandomAccessFile#writeChar() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestDiskUtils.java    From rubix with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetCacheSizeMB_WithHoledFile() throws IOException
{
  String fileName = testDirectory + "/testfile";
  File dirName = new File(testDirectory);
  RandomAccessFile rafile = new RandomAccessFile(fileName, "rw");
  rafile.seek(20000000);
  for (int i = 0; i < 1100000; i++) {
    rafile.writeChar('a' + i % 10);
  }
  rafile.close();
  File file = new File(fileName);
  long dsize = DiskUtils.getDirectorySizeInMB(dirName);
  assertTrue(dsize == 2, "DiskSize is reported :" + dsize + " but expected : 2");
  file.deleteOnExit();
}
 
Example 2
Source File: RandomAccessFileDemo.java    From Java with Artistic License 2.0 6 votes vote down vote up
private static void write() throws IOException {
	// ��������
	RandomAccessFile raf = new RandomAccessFile("raf.txt", "rw");

	// ���
	raf.writeInt(100);
	raf.writeChar('a');
	// raf.writeUTF("hello");
	raf.writeUTF("����ϼ");

	raf.seek(1000);
	raf.writeUTF("����");

	// �ͷ���Դ
	raf.close();
}
 
Example 3
Source File: RandomAccessFileDemo.java    From code with Apache License 2.0 5 votes vote down vote up
@Test
public void testWrite() throws IOException {
    // 1、创建随机访问流对象
    RandomAccessFile raf = new RandomAccessFile("raf.txt", "rw");
    // 2、写入数据
    raf.writeInt(100);
    raf.writeChar('a');
    raf.writeUTF("中国");
    // 3、关闭资源
    raf.close();
}
 
Example 4
Source File: RandomAccessFileTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.io.RandomAccessFile#readChar()
 */
public void test_readChar() throws IOException {
    // Test for method char java.io.RandomAccessFile.readChar()
    RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
    raf.writeChar('T');
    raf.seek(0);
    assertEquals("Incorrect char read/written", 'T', raf.readChar());
    raf.close();
}
 
Example 5
Source File: RandomAccessFileTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.io.RandomAccessFile#writeChar(int)
 */
public void test_writeCharI() throws IOException {
    // Test for method void java.io.RandomAccessFile.writeChar(int)
    RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
    raf.writeChar('T');
    raf.seek(0);
    assertEquals("Incorrect char read/written", 'T', raf.readChar());
    raf.close();
}