Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
17
Task/Truncate-a-file/Java/truncate-a-file.java
Normal file
17
Task/Truncate-a-file/Java/truncate-a-file.java
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
public class TruncFile {
|
||||
public static void main(String[] args) throws IOException{
|
||||
if(args.length < 2){
|
||||
System.out.println("Usage: java TruncFile fileName newSize");
|
||||
return;
|
||||
}
|
||||
//turn on "append" so it doesn't clear the file
|
||||
FileChannel outChan = new FileOutputStream(args[0], true).getChannel();
|
||||
long newSize = Long.parseLong(args[1]);
|
||||
outChan.truncate(newSize);
|
||||
outChan.close();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue