當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。