---
title: Java IO
category: Java
tag:
- Java IO
- Java
---
IO
##
**Decorator**
IO
`FilterInputStream` `FilterOutputStream` `InputStream` `OutputStream`
`BufferedInputStream`()`DataInputStream` `FilterInputStream` `BufferedOutputStream``DataOutputStream``FilterOutputStream`
`BufferedInputStream` `FileInputStream`
`BufferedInputStream`
```java
public BufferedInputStream(InputStream in) {
this(in, DEFAULT_BUFFER_SIZE);
}
public BufferedInputStream(InputStream in, int size) {
super(in);
if (size ... events)
throws IOException;
```
3
- `StandardWatchEventKinds.ENTRY_CREATE`
- `StandardWatchEventKinds.ENTRY_DELETE` :
- `StandardWatchEventKinds.ENTRY_MODIFY` :
`register` `WatchKey` `WatchKey`
```java
WatchKey key;
while ((key = watchService.take()) != null) {
for (WatchEvent event : key.pollEvents()) {
// WatchEvent
}
key.reset();
}
```
`WatchService` daemon thread
```java
class PollingWatchService
extends AbstractWatchService
{
// daemon thread
private final ScheduledExecutorService scheduledExecutor;
PollingWatchService() {
scheduledExecutor = Executors
.newSingleThreadScheduledExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setDaemon(true);
return t;
}});
}
void enable(Set> events, long period) {
synchronized (this) {
//
this.events = events;
//
Runnable thunk = new Runnable() { public void run() { poll(); }};
this.poller = scheduledExecutor
.scheduleAtFixedRate(thunk, period, period, TimeUnit.SECONDS);
}
}
}
```
##
- Patterns in Java APIshttp://cecs.wright.edu/~tkprasad/courses/ceg860/paper/node26.html
- Java IO https://time.geekbang.org/column/article/204845
- sun.nio java - RednaxelaFX https://www.zhihu.com/question/29237781/answer/43653953