|
Displaying characters in many ways.
I am having trouble getting this going....
I am trying to:
1. System.out every other letter on the first line of my text file.
2. System.out (print out) every other line
3. and finally just characters at positions 26-53 of my last line.
Just an exercise I am working on to learn more about I/O files.
Here is my text file:
This is a basic test file to test out how
a file can be read into the super duper
application and how we can extract certain
characters at several different positions
to do whatever we need to with them.
This java program should be able to open a file
and print out every other letter on the first line;
and then print out every other line, and then finally
print characters 26-53 of this last line. I hope it has enough characters.
import java.io.*;
import java.util.*;
public class demo
{
public static void main(String args[])
{
String data = null;
int recCount = 0;
try
{
FileReader fr = new FileReader("C:\\Development\\demo.txt");
BufferedReader br = new BufferedReader(fr);
data = new String();
while ((data = br.readLine()) != null)
{
recCount++;
System.out.println(data);
}
}
catch (IOException e)
{
System.out.println("IOException error!");
e.printStackTrace();
}
}
}
|