Are you learning Java from online tutorials? If so, I sincerely recommend getting a book, esp. to begin with and get a solid background of the language. I've been promoting Bruce Eckel's Thinking in Java books since I originally picked Java up from the 2nd edition (when J2SDK1.3 was out), and I think they're the best free resources available for learning Java. They're available for free in downloadable form, but you can also buy them on paper or CD-ROM.
http://www.mindview.net/Books/TIJ/ -- the 2nd edition was about a two week read (while doing other things of course), and I expect the third edition to take about as long to read.
Also of interest if you're using Java 1.4+ will be the java.nio packages; they're more complex to use because they're lower-level, but that also makes the new I/O system more efficient. This example, which I borrowed from Thinking in Java, 3rd Edition by Bruce Eckel (see above) will copy one file to another using the new I/O system (bytebuffers and channels):
Code:
//: c12:ChannelCopy.java
// Copying a file using channels and buffers
// {Args: ChannelCopy.java test.txt}
// {Clean: test.txt}
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class ChannelCopy {
private static final int BSIZE = 1024;
public static void main(String[] args) throws Exception {
if(args.length != 2) {
System.out.println("arguments: sourcefile destfile");
System.exit(1);
}
FileChannel
in = new FileInputStream(args[0]).getChannel(),
out = new FileOutputStream(args[1]).getChannel();
ByteBuffer buffer = ByteBuffer.allocate(BSIZE);
while(in.read(buffer) != -1) {
buffer.flip(); // Prepare for writing
out.write(buffer);
buffer.clear(); // Prepare for reading
}
}
} ///:~