> Quick and dirty hack: use trim(), which removes all leading and
> trailing whitespaces from a string.
Hack to do what? It certainly doesn't do what the OP asked for. I can
present all sorts of even quicker hacks, if we're dropping the
requirement that it works properly.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Mark Thomas - 10 May 2006 10:27 GMT
>> Quick and dirty hack: use trim(), which removes all leading and
>> trailing whitespaces from a string.
>
> Hack to do what? It certainly doesn't do what the OP asked for. I can
> present all sorts of even quicker hacks, if we're dropping the
> requirement that it works properly.
How about something like this:
import java.io.*;
public class Copier {
public static void main(String[] args) {
try {
BufferedReader in = new BufferedReader
(new FileReader("file1.txt"));
PrintWriter out = new PrintWriter(new FileWriter("file2.txt"));
String line = null;
while ((line = in.readLine()) != null) {
out.write(line);
}
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
as readLine() strips the line terminators as it goes, and write()
doesn't add them.
Mark