English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Java help me with this please...............

Create a program that will open a file in the project with the text dog,cat,mouse,horse..........the program output should be :

dog
cat
mouse
horse

2007-02-04 17:10:44 · 2 answers · asked by y0ger_19 4 in Computers & Internet Programming & Design

using FileReader

2007-02-04 17:23:24 · update #1

2 answers

import java.io.*;
import java.util.*;

public class Anim
{
public static void main(String[] args) throws Exception{
String file;
BufferedReader fromFile =
new BufferedReader(new FileReader("animal.txt"));

file=fromFile.readLine();
String delimiter = ","; //string to split the given one by
String[] tokenzArray = file.split( delimiter ); //our tokenz array
for ( String part: tokenzArray ){
System.out.println(""+part+"");
}
}
}
Here is the solution. =)

2007-02-04 21:23:07 · answer #1 · answered by Geinius 3 · 0 0

You need to use string manipulation functions available in Java. Read the file as a string and parse it taking ',' as the needle and output the read string as another another string into Output file ending with newline character.

How to use string functions, read here :

http://java.sun.com/j2se/1.3/docs/api/index.html
http://home.cogeco.ca/~ve3ll/jatutor7.htm

2007-02-04 17:52:39 · answer #2 · answered by Ankur Jain 2 · 0 0

fedest.com, questions and answers