M
moonhkt
Hi All
Do you know how to write data to file as below format
first data is readable , second data is byte value
for (int i = 192 ; i < 223 ; i++) {
for ( int j = 129 ; i <= 223 , j++) {
output to file i ,j ;
output to byte of i , byte f j;
}
}
I does not know how to update below file.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class build_binary {
public static void main(String[] args) {
String phrase = new String(new byte [] {
(byte) 0xe5, (byte) 0x87, (byte) 0x8c
});
File aFile = new File("test.txt");
FileOutputStream file = null;
try {
file = new FileOutputStream(aFile, true);
} catch (FileNotFoundException e) {
e.printStackTrace(System.err);
}
FileChannel outChannel = file.getChannel();
ByteBuffer buf = ByteBuffer.allocate(phrase.length());
byte[] bytes = phrase.getBytes();
buf.put(bytes);
buf.flip();
try {
outChannel.write(buf);
file.close();
} catch (IOException e) {
e.printStackTrace(System.err);
}
}
}
Do you know how to write data to file as below format
first data is readable , second data is byte value
for (int i = 192 ; i < 223 ; i++) {
for ( int j = 129 ; i <= 223 , j++) {
output to file i ,j ;
output to byte of i , byte f j;
}
}
I does not know how to update below file.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class build_binary {
public static void main(String[] args) {
String phrase = new String(new byte [] {
(byte) 0xe5, (byte) 0x87, (byte) 0x8c
});
File aFile = new File("test.txt");
FileOutputStream file = null;
try {
file = new FileOutputStream(aFile, true);
} catch (FileNotFoundException e) {
e.printStackTrace(System.err);
}
FileChannel outChannel = file.getChannel();
ByteBuffer buf = ByteBuffer.allocate(phrase.length());
byte[] bytes = phrase.getBytes();
buf.put(bytes);
buf.flip();
try {
outChannel.write(buf);
file.close();
} catch (IOException e) {
e.printStackTrace(System.err);
}
}
}