File Extension Changer program

A

Andrew Tegala

Dear All,

I would like help with creation of a few Java Programs.

Mainly, a program to change the extension of a file, from .txt to
..lst. It needs to take teh filename as a command line argument and
outputs a 'list' file.

For example the text file, "test.txt"
This is a
small text file
The end.

Would be produce a file, "test.lst"

1 This is a
2 small text file
3 The end.

Another program I need help with is to take student details from a
text file and output the e-mail address.

Using the String, StringTokenizer and StringBuffer classes.

The details are in the form of "surname:firstname:id"

output should be

first character of firstname + first character of surname + last for
digits of the id + "domain.ac.uk"

e.g. makeEmail("Smith:John:83702794") returns "(e-mail address removed)"

Your help is greatly appreciated. Kind regards,

Andrew Tegala
 
N

Neomorph

Dear All,

I would like help with creation of a few Java Programs.

Looks like perfect student work to me ;-)
I'll give you a few pointers, but you'll have to do the grunt work
yourself...
Mainly, a program to change the extension of a file, from .txt to
.lst. It needs to take teh filename as a command line argument and
outputs a 'list' file.

For example the text file, "test.txt"
This is a
small text file
The end.

Reading text files is easiest with the FileReader class.
To read lines from a text file, you can use either the BufferedReader or
the LinenumberReader on top of the FileReader. Both have a .readLine()
method. The second one even keeps track of the line number...
Would be produce a file, "test.lst"

1 This is a
2 small text file
3 The end.

Writing a file is done using the FileWriter on which you could use a
PrintWriter for the 'printing' of lines and other things to the file.

Changing the extension is easy using String's lastIndexOf method (searching
for the dot).
Another program I need help with is to take student details from a
text file and output the e-mail address.

Using the String, StringTokenizer and StringBuffer classes.

The details are in the form of "surname:firstname:id"

output should be

first character of firstname + first character of surname + last for
digits of the id + "domain.ac.uk"

e.g. makeEmail("Smith:John:83702794") returns "(e-mail address removed)"

StringTokenizer is used to split a string according to a certain character
(or multiple characters).
Use the .nextToken() to get the seperate parts one at a time.

You're going to need Strings .substring() .toLowerCase() and StringBuffer's
..append().
Your help is greatly appreciated. Kind regards,

Andrew Tegala

Check out the JavaDoc documentation that is seperately downloadable from
the JDK - it's the best reference you can use.

Cheers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top