Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/byhieg/JavaTutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
byhieg committed Apr 16, 2017
2 parents c7e8bbb + 212ff13 commit c115f0c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/cn/byhieg/algorithmtutorial/Sort.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ public int partition(int[] nums, int low, int high) {
int x = nums[i];
while (i < j) {
//从右向左找到nums[j]小于x的元素
while (i < j && nums[j] > x) j--;
while (i < j && nums[j] >= x) j--;
if (i < j) {
nums[i] = nums[j];
i++;
}

//从左向右找到nums[i]大于x的元素
while (i < j && nums[i] < x) i++;
while (i < j && nums[i] <= x) i++;
if (i < j) {
nums[j] = nums[i];
j--;
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/cn/byhieg/niotutorial/NioTest.java
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();
}
}
5 changes: 5 additions & 0 deletions src/main/java/cn/byhieg/niotutorial/read_file.txt
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.

0 comments on commit c115f0c

Please sign in to comment.