Copy the file from the large file

Create the new file from large file, using File Channel and ByteBuffer: Example :  import java.io.IOException; import java.net.URI; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.Date; public class CopyLargeFileExample { public static void main(String args[]) throws IOException { long startTime = new Date().getTime(); // args[0] — Input source file // args[1]… Read More

Java NIO : write small size file using FileChannel

Write the file Using ByteBuffer and FileChannel from String: import java.io.IOException; import java.net.URI; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; public class WriteFileUsingFileChannel { public static void main(String args[]) throws IOException { String content = “Text content”; Path file = Paths.get(URI.create(“file:///D:/TestFile.txt”)); FileChannel fileChannel = FileChannel.open(file, StandardOpenOption.CREATE, StandardOpenOption.WRITE); ByteBuffer buffer = ByteBuffer.allocate(content.length()); buffer.put(content.getBytes());… Read More

Java NIO : read small size file using FileChannel

Read the file Using ByteBuffer and file Size: import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.file.Path; import java.nio.file.Paths; public class ReadFileUsingFileChannel { public static void main(String args[]) throws IOException { String inputFile = “D:\\SampleFile.txt”; //Set the Path with input file Path file = Paths.get(inputFile); //Open the file FileChannel fileChannel = FileChannel.open(file); //Get the Size of… Read More

How to change the hostname in Linux

This article describes the how the change the hostname in Linux machine. Let’s start. Open the network file. # sudo vi /etc/sysconfig/network Modify the HOSTNAME= value with your domain name. Example hostname is “myhostname” HOSTNAME = myhostname To access with in the server add it in /etc/hosts file 127.0.0.1 myhostname Run the “hostname” command. This command… Read More