I am a beginner in programming.
I am trying to read the first word of every line from a file, and I want to write all of the first words to another file.
I have done the following code.
import java.io.*;
import java.nio.charset.Charset;
public class ReadWord
{
public static void main(String args[])
{
BufferedReader br;
String line;
int count = 0;
InputStream fis = null;
try
{
fis = new FileInputStream("D:/Android/WorkSpace10-1/FileHandling.Java/src/123.txt");
br = new BufferedReader( new InputStreamReader(fis, Charset.forName("UTF-8")));
while((line = br.readLine())!= null)
{
System.out.println(line);
String result[] = line.split(",");
while(line!=",")
{
System.out.println(result);
}
}
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
try
{
fis.close();
}
catch(IOException ie)
{
System.out.println(ie);
}
}
}
}
Please help me out how to read the first word of every line and write that word to another file.
Files!