Latest Entries »

Enable Telnet at Windows 7

By default, Telnet feature is disable by Windows 7. If you want to enable this feature, see following step.

1. From Start Menu, select Control Panel

enable-telnet-01

enable-telnet-01

2. Then click Programs

enable-telnet-02

enable-telnet-02

3. Click Turn Windows features on or off

enable-telnet-03

enable-telnet-03

4. Check Telnet Client, then OK.

enable-telnet-04

enable-telnet-04

Note that you must logged in as Administrator to do this step. :)

Aku, Karena Kau

Aku adalah duri dalam daging
Aku adalah buih di lautan
Aku adalah buram
Aku tiada berarti

Aku adalah marah
Aku tidaklah penting
Aku bukan cendekiawan
Aku bukan yang terbaik

Kau yang mengutuk Aku
Kau yang tidak peduli
Kau selalu jadi penakut
Kau buat aku tersudut

Copy File in Java

Now we try to copy file in Java. We can do that by copy contents from one file to another file. Sounds difficult huh? Not really. First, we need import java.io package.

Then we creates a new File instance for the file name passed as parameter, and creates another InputStream instance for the input object and OutputStream instance for the output object passed as parameter.

And then create byte type buffer for buffering the contents of one file, and write to another specified file. Hm.. thats is the recipe of ‘Copy File in Java’.

Here the example code:

import java.io.*;

public class CopyFile{
	public static void main(String[] args){
		try{
			File f1 = new File(args[0]);
			File f2 = new File(args[1]);
			InputStream in = new FileInputStream(f1);
			OutputStream out = new FileOutputStream(f2);

			byte[] buf = new byte[1024];
			int len;
			while ((len = in.read(buf)) > 0){
				out.write(buf, 0, len);
			}
			in.close();
			out.close();
			System.out.println("File copied.");
		}catch(IOException e){
			e.printStackTrace();
		}
	}
}

copy file example

copy file example

Now, you try :mrgreen:

Get File Size in Java

In java, you can use class java.io.File to get file size. Just see the example:

import java.io.*;

public class FileSize {
	public static void main(String args[]) {
		File file = new File("C:/test.txt");
		long fSize = file.length();
		long fSizeInKB = fSize / 1024;
		System.out.println("Size of File is: " + fSizeInKB + " KB");
	}
}

Its easy :mrgreen:

Delay in Java

This time, we learn how we can make program so that there are delay between execution of program.

We can using sleep() method. We can passing value in milisecond (remember that 1 second equal to 1000 milisecond).
The sleep method can throws an InterruptedException. Then we must have write sleep() method within try-catch block.

View full article »

Follow

Get every new post delivered to your Inbox.