File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
java/com/brianway/java/nio/tutorial Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .brianway .java .nio .tutorial ;
2
+
3
+ import com .brianway .learning .java .nio .tutorial .BufferDemo ;
4
+ import org .junit .Assert ;
5
+ import org .junit .Test ;
6
+
7
+ import java .io .IOException ;
8
+ import java .io .RandomAccessFile ;
9
+ import java .nio .channels .FileChannel ;
10
+
11
+ /**
12
+ * FileChannel测试
13
+ *
14
+ * @auther brian
15
+ * @since 2019/6/24 23:00
16
+ */
17
+ public class FileChannelTest {
18
+ private String dir = BufferDemo .class .getResource ("/" ).getPath ();
19
+ private String path = BufferDemo .class .getResource ("/" ).getPath () + "fileChannel.txt" ;
20
+
21
+ @ Test
22
+ public void testTruncate () throws IOException {
23
+ RandomAccessFile aFile = new RandomAccessFile (dir + "truncate.txt" , "rw" );
24
+ FileChannel channel = aFile .getChannel ();
25
+ int size = 10 ;
26
+ // Truncates this channel's file to the given size.
27
+ channel .truncate (size );
28
+ long fileSize = channel .size ();
29
+ Assert .assertEquals (size , fileSize );
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ asdasdas
2
+ ahfsadkjhsdfkjl
3
+ 23232323
4
+ 2323
Original file line number Diff line number Diff line change
1
+ asdasdas
2
+ ahfsadkjhsdfkjl
3
+ 23232323
4
+ 2323
You can’t perform that action at this time.
0 commit comments