Get Unbuffered IO support from java.nio.file.Files in Java

Description

The following code shows how to get Unbuffered IO support from java.nio.file.Files.

Example


/*from   ww w  .  j  ava2  s. co m*/
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

public class Main {

  public static void main(String[] args) throws IOException {
    Path file = Paths.get("/home/docs/users.txt");
    Path newFile = Paths.get("/home/docs/newUsers.txt");
    try (InputStream in = Files.newInputStream(file); 
         OutputStream out = Files.newOutputStream(newFile,StandardOpenOption.CREATE, 
                 StandardOpenOption.APPEND)) {
        int data = in.read();
        while (data != -1){
            out.write(data);
            data = in.read();
        }
    }     

  }
}




















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip