当前位置: 首页>>代码示例>>Java>>正文


Java RandomAccessFile.writeBytes方法代码示例

本文整理汇总了Java中java.io.RandomAccessFile.writeBytes方法的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessFile.writeBytes方法的具体用法?Java RandomAccessFile.writeBytes怎么用?Java RandomAccessFile.writeBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.RandomAccessFile的用法示例。


在下文中一共展示了RandomAccessFile.writeBytes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPlatformWithAbsolutePath

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public void testPlatformWithAbsolutePath() throws Exception {
    File wd = new File(getWorkDir(), "currentdir");
    wd.mkdirs();
    URL u = Lookup.class.getProtectionDomain().getCodeSource().getLocation();
    File utilFile = new File(u.toURI());
    assertTrue("file found: " + utilFile, utilFile.exists());
    File root = utilFile.getParentFile().getParentFile().getParentFile();
    File bin = new File(root,"bin");
    File newBin = new File(wd,"bin");
    newBin.mkdirs();
    File newEtc = new File(wd,"etc");
    newEtc.mkdirs();
    File[] binFiles = bin.listFiles();
    for (File f : binFiles) {
        File newFile = new File(newBin,f.getName());
        FileChannel newChannel = new RandomAccessFile(newFile,"rw").getChannel();
        new RandomAccessFile(f,"r").getChannel().transferTo(0,f.length(),newChannel);
        newChannel.close();
    }
    RandomAccessFile netbeansCluster = new RandomAccessFile(new File(newEtc,"netbeans.clusters"),"rw");
    netbeansCluster.writeBytes(utilFile.getParentFile().getParent()+"\n");
    netbeansCluster.close();
    String str = "1 * * * *";
    run(wd, str);
    
    String[] args = MainCallback.getArgs(getWorkDir());
    assertNotNull("args passed in", args);
    List<String> a = Arrays.asList(args);
    if (!a.contains(str)) {
        fail(str + " should be there: " + a);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:PlatformWithAbsolutePathTest.java

示例2: filewrite

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public void filewrite( String s )
{
	try {
		RandomAccessFile w =
			new RandomAccessFile( target, "rw" );
		w.seek( w.length() );
		w.writeBytes( s );
		w.close();
	} catch ( Exception e ) {
		System.out.println("Debug output file write failed");
	}
}
 
开发者ID:brok1n,项目名称:SerialAssistant,代码行数:13,代码来源:Zystem.java

示例3: writeToFile

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public void writeToFile() {
    try {
        RandomAccessFile randomAccessFile = new RandomAccessFile("output.txt", "rw");
        String message1 = "Hello there!";
        String message2 = "It's a bright and sunny day today!";
        int x = 12;
        randomAccessFile.writeBytes(x + "\n");
        randomAccessFile.writeBytes(message1 + "\n");
        randomAccessFile.writeBytes(message2 + "\n");
    } catch (FileNotFoundException fnfe) {
        System.out.println("File doesn't exist");
    } catch (IOException ioe) {
        System.out.println("Can't write to the file");
    }
}
 
开发者ID:kmhasan-class,项目名称:spring2017java,代码行数:16,代码来源:FileIODemoSection3.java

示例4: prepareAudioRecord

import java.io.RandomAccessFile; //导入方法依赖的package包/类
private boolean prepareAudioRecord(Context context, File recordFile, int audioRecordChannelConfig, int chanelNumber, int audioRecordAudioFormat, int nbBitsPerSample)
{
	try
	{
		if (audioRecord.getState() == AudioRecord.STATE_INITIALIZED)
		{
			audioRecordRandomAccessFile = new RandomAccessFile(recordFile.getAbsolutePath(), "rw");
			audioRecordRandomAccessFile.setLength(0);
			audioRecordRandomAccessFile.writeBytes("RIFF"); // 00 - Marks the file as a riff file
			audioRecordRandomAccessFile.writeInt(0); // 04 - Size of the overall file
			audioRecordRandomAccessFile.writeBytes("WAVE"); // 08 - File Type Header
			audioRecordRandomAccessFile.writeBytes("fmt "); // 12 - Format chunk marker
			audioRecordRandomAccessFile.writeInt(Integer.reverseBytes(16)); // 16 - Length of format data as listed above
			audioRecordRandomAccessFile.writeShort(Short.reverseBytes((short) 1)); // 20 - Type of format
			audioRecordRandomAccessFile.writeShort(Short.reverseBytes((short) chanelNumber)); // 22 - Number of Channels
			audioRecordRandomAccessFile.writeInt(Integer.reverseBytes(audioRecordSampleRate)); // 24 - Sample Rate
			audioRecordRandomAccessFile.writeInt(Integer.reverseBytes(audioRecordSampleRate * chanelNumber * (short)nbBitsPerSample / 8)); // 28 - ByteRate
			audioRecordRandomAccessFile.writeShort(Short.reverseBytes((short)(chanelNumber * nbBitsPerSample / 8))); // 32 - Alignment
			audioRecordRandomAccessFile.writeShort(Short.reverseBytes((short) nbBitsPerSample)); // 34 - Bits per sample
			audioRecordRandomAccessFile.writeBytes("data"); // 36 - "data" chunk header
			audioRecordRandomAccessFile.writeInt(0); // 40 - Size of the data section
			audioRecordBuffer = new byte[audioRecordPeriodInFrames * (short)nbBitsPerSample / 8 * chanelNumber];
		}
		else
		{
			Log.w("RecordFileWriter", "prepareAudioRecord : " + context.getString(R.string.log_record_file_writer_error_audiorecord_prepare));
			databaseManager.insertLog(context, "" + context.getString(R.string.log_record_file_writer_error_audiorecord_prepare), new Date().getTime(), 2, false);
			return false;
		}
	}
	catch (Exception e)
	{
		Log.w("RecordFileWriter", "prepareAudioRecord : " + context.getString(R.string.log_record_file_writer_error_audiorecord_prepare) + " : " + e);
		databaseManager.insertLog(context, "" + context.getString(R.string.log_record_file_writer_error_audiorecord_prepare), new Date().getTime(), 2, false);
		return false;
	}
	
	return true;
}
 
开发者ID:vassela,项目名称:AC2RD,代码行数:40,代码来源:RecordFileWriter.java

示例5: append

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * @param fileName
 * @param content
 */
public static void append(String fileName, String content) {
    try {
        RandomAccessFile randomFile = new RandomAccessFile(fileName, "rw");
        long fileLength = randomFile.length();
        randomFile.seek(fileLength);
        randomFile.writeBytes(content);
        randomFile.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Prisma-illya,项目名称:PMCL,代码行数:16,代码来源:filewrite.java

示例6: updateData

import java.io.RandomAccessFile; //导入方法依赖的package包/类
private void updateData(byte[] text, String javaHome, String end,RandomAccessFile file) throws IOException {
	String data=new String(text);
	data=StringUtils.replace(data, end, javaHome);
	file.setLength(data.length());
	file.writeBytes(data);
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:7,代码来源:PreStartActivity.java


注:本文中的java.io.RandomAccessFile.writeBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。