forked from byhieg/JavaTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/byhieg/JavaTutorial
- Loading branch information
Showing
3 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package cn.byhieg.niotutorial; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.RandomAccessFile; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.FileChannel; | ||
|
||
/** | ||
* Created by shiqifeng on 2017/4/10. | ||
* Mail byhieg@gmail.com | ||
*/ | ||
public class NioTest { | ||
|
||
public static void main(String[] args) throws IOException { | ||
String s = File.separator; | ||
RandomAccessFile aFile = new RandomAccessFile("D:" + s + "read_file.txt","rw"); | ||
FileChannel inChannel = aFile.getChannel(); | ||
|
||
ByteBuffer buf = ByteBuffer.allocate(48); | ||
int bytesRead = inChannel.read(buf); | ||
while (bytesRead != -1) { | ||
buf.flip(); | ||
while (buf.hasRemaining()) { | ||
System.out.print((char) buf.get()); | ||
} | ||
|
||
buf.clear(); | ||
bytesRead = inChannel.read(buf); | ||
} | ||
|
||
aFile.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
I don't know what I do now is right, those are wrong, and when I finally die then I know these. | ||
So what I can do now is to try to do everything well, and then wait to die . | ||
Sometimes I can be very happy to talk to everyone, can be very presumptuous, but no one knows, | ||
it is but very deliberately camouflage, camouflage; I can make him very happy very happy, | ||
but couldn't find the source of happiness, just giggle. |