Professional Documents
Culture Documents
17 Nio2
17 Nio2
Java SE
Contents
• Overview
• File System
• Directory System
DirectoryStream<Path> directory =
Files.newDirectoryStream(path);
for(Path p : directory)
this.showChildren(p, bias + BIAS);
}
}
Input & Output
• Java တ0င& ဖiuင&မ3,4ကiu ဖတ&ယPရ,တ0င&၎င&4 eရ4သ,4ရ,တ0င&၎င&4၊ Stream
မ3,4၊ Reader Writer မ3,41'င&2 Channel မ3,4ကiu အသu546ပu1iuင&ပIသည&
APPEND READ
CREATE SPARSE
CREATE_NEW SYNC
DELETE_ON_CLOSE TRUNCATE_EXISTING
DSYNC WRITE
I/0 Stream
public static void doStreamSample(Path path) {
try (InputStream input = Files.newInputStream(path);
OutputStream out = Files.newOutputStream(
path, StandardOpenOption.APPEND)) {
} catch (IOException e) {
e.printStackTrace();
}
}
Reader & Writer
public static void doReaderSample(Path path) {
} catch (IOException e) {
e.printStackTrace();
}
}
Byte Channel
public static void doSeekChennelSample(Path path) {
try (SeekableByteChannel chennel =
Files.newByteChannel(path);
SeekableByteChannel writeChannel =
Files.newByteChannel(path,
StandardOpenOption.WRITE,
StandardOpenOption.APPEND)) {
} catch (IOException e) {
e.printStackTrace();
}
}
File Channel
public static void doFileChannelSample(Path path) {
} catch (IOException e) {
e.printStackTrace();
}
}
Using small File
public static void easyReadSample(Path path) throws IOException {
// Read Bytes
byte [] bytes = Files.readAllBytes(path);
// Read Lines
List<String> lines = Files.readAllLines(path, Charset.defaultCharset());
// Write bytes
Files.write(path, bytes, StandardOpenOption.APPEND);