List of usage examples for java.io RandomAccessFile write
public void write(byte b[]) throws IOException
From source file:Main.java
public static void main(String[] args) { try {//from w w w. j a v a 2 s .co m byte[] b = { 1 }; RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); raf.write(b); // set the file pointer at 0 position raf.seek(0); System.out.println(raf.readByte()); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {/*from w w w . j a v a 2 s .c om*/ int b1 = 15; int b2 = 20; RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); raf.write(b1); // set the file pointer at 0 position raf.seek(0); System.out.println(raf.readByte()); raf.write(b2); raf.seek(1); System.out.println(raf.readByte()); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:BridgeBasics.java
public static void main(String args[]) throws Exception { RServices rs = DirectJNI.getInstance().getRServices(); rs.consoleSubmit("k=function(x){x*5}"); System.out// ww w . j a va2 s .c o m .println("////////////////////////////////" + rs.callAndConvert(new RFunctionObjectName("k"), 45)); //rs.putAndAssign(new RUnknown(o.getValue()), "b"); //System.out.println("-------------------------------"+rs.print("h")); /* RServices rs = ServerManager.createR("toto"); RObject ro1 = rs.getObject("structure(list(1,2), caption = \"foo\")"); RObject ro2 = rs.getReference("structure(list(1,2), caption = \"foo\")"); System.out.println(rs.callAndConvert("str", ro1)); System.out.println(rs.callAndConvert("str", ro2)); rs.die(); if (true) return; */ rs = DirectJNI.getInstance().getRServices(); GDDevice device = rs.newDevice(400, 400); rs.consoleSubmit("plot(pressure)"); System.out.println(rs.getStatus()); byte[] buffer = device.getPng(); RandomAccessFile raf = new RandomAccessFile("c:/te.png", "rw"); raf.setLength(0); raf.write(buffer); raf.close(); //rs.evaluate("x=2;y=8",2); /* RS3 s3=(RS3)rs.getReference("packageDescription('stats')"); System.out.println("s="+Arrays.toString(s3.getClassAttribute())); s3.setClassAttribute(new String[] {s3.getClassAttribute()[0], "aaa"}); rs.assignReference("f",s3); //rs.call("print",new RObjectName("f")); //System.out.println("log=" + rs.getStatus()); rs.consoleSubmit("print(class(f))"); System.out.println("log=" + rs.getStatus()); RChar s = (RChar) rs.call("paste", new RChar("str1"), new RChar("str2"), new RNamedArgument("sep", new RChar( "--"))); System.out.println("s=" + s); */ System.exit(0); }
From source file:Main.java
public static void main(String[] argv) throws Exception { RandomAccessFile file = new RandomAccessFile("scores.html", "rw"); for (int i = 1; i <= 6; i++) { System.out.println(file.readLine()); }/*from w w w .ja va2s.c om*/ long current = file.getFilePointer(); file.seek(current + 6); file.write("34".getBytes()); for (int i = 1; i <= 5; i++) { System.out.println(file.readLine()); } current = file.getFilePointer(); file.seek(current + 6); file.write("27".getBytes()); file.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { RandomAccessFile raf = new RandomAccessFile("a.dat", "rw"); int x, y;/*from ww w. java2 s.c o m*/ for (long i = 0, j = raf.length() - 1; i < j; i++, j--) { raf.seek(i); x = raf.read(); raf.seek(j); y = raf.read(); raf.seek(j); raf.write(x); raf.seek(i); raf.write(y); } raf.close(); }
From source file:Main.java
public static void main(String[] args) { try {//w w w .ja v a 2 s .com RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); // write something in the file raf.writeUTF("Hello World from java2s.com"); // set the file pointer at 0 position raf.seek(0); // read byte System.out.println(raf.readByte()); // set the file pointer at 0 position raf.seek(0); // write 0 at the start raf.write(0); // read byte System.out.println(raf.readByte()); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {/*from www . j a v a 2 s .c o m*/ RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); // write something in the file raf.writeUTF("Hello World from java2s.com"); // set the file pointer at 0 position raf.seek(0); // read boolean System.out.println(raf.readBoolean()); // set the file pointer at 0 position raf.seek(0); // write 0 at the start raf.write(0); // read boolean System.out.println(raf.readBoolean()); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void append(String fileName, byte[] bytes) throws Exception { File f = new File(fileName); long fileLength = f.length(); RandomAccessFile raf = new RandomAccessFile(f, "rw"); raf.seek(fileLength);//from w w w . ja v a2s.com raf.write(bytes); raf.close(); }
From source file:Main.java
public static void WriteTxtFile(Context context, String strcontent) { String strContent = strcontent + "\n"; try {//from ww w.j a v a 2 s .com File file = new File(context.getCacheDir() + File.separator + "wanjia.txt"); if (!file.exists()) { file.createNewFile(); } RandomAccessFile raf = new RandomAccessFile(file, "rw"); raf.seek(file.length()); raf.write(strContent.getBytes()); raf.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.srlutils.Files.java
/** write txt to filename */ public static void writetofile(String txt, String filename) { try {//from ww w .ja va 2 s .c o m String mode = "rw"; RandomAccessFile fid = new RandomAccessFile(filename, mode); fid.setLength(0); fid.write(txt.getBytes()); fid.close(); } catch (Exception ex) { throw rte(ex, "failed to write string: %s, to file: %s", Text.summary(txt), filename); } }