Skip to content

Commit 849f9f0

Browse files
committed
nothing
1 parent 212ff13 commit 849f9f0

1 file changed

Lines changed: 31 additions & 13 deletions

File tree

src/main/java/cn/byhieg/niotutorial/NioTest.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.io.RandomAccessFile;
77
import java.nio.ByteBuffer;
88
import java.nio.channels.FileChannel;
9+
import java.util.ArrayList;
10+
import java.util.List;
911

1012
/**
1113
* Created by shiqifeng on 2017/4/10.
@@ -14,22 +16,38 @@
1416
public class NioTest {
1517

1618
public static void main(String[] args) throws IOException {
17-
String s = File.separator;
18-
RandomAccessFile aFile = new RandomAccessFile("D:" + s + "read_file.txt","rw");
19-
FileChannel inChannel = aFile.getChannel();
20-
21-
ByteBuffer buf = ByteBuffer.allocate(48);
22-
int bytesRead = inChannel.read(buf);
23-
while (bytesRead != -1) {
24-
buf.flip();
25-
while (buf.hasRemaining()) {
26-
System.out.print((char) buf.get());
19+
for (int i = 2; i <= 100; i++) {
20+
if(i == 2 || i == 5 || i == 7 || i == 3){
21+
System.out.print(i + " ");
22+
continue;
23+
}
24+
if (i % 2 == 0 || i % 3 == 0 || i % 5 == 0 || i % 7 == 0) {
25+
continue;
2726
}
2827

29-
buf.clear();
30-
bytesRead = inChannel.read(buf);
28+
System.out.print(i + " ");
29+
}
30+
System.out.println();
31+
for (int i = 2 ; i <= 100;i++){
32+
if (isPrime(i)){
33+
System.out.print(i + " ");
34+
}
3135
}
36+
}
37+
38+
39+
public static boolean isPrime(int n){
40+
if(n < 2){
41+
return false;
42+
}
43+
for (int i = 2; i <= Math.sqrt(n);i++){
44+
if (n % i == 0){
45+
return false;
46+
}
47+
}
48+
return true;
3249

33-
aFile.close();
3450
}
51+
52+
3553
}

0 commit comments

Comments
 (0)