There are a couple of ways you could probably do this. Here are two that aren't very different:
import java.io.*;
public class Main {
public static void main(String[] args) {
char[] array = new char[30];
int cnt;
try {
FileReader ifp = new FileReader("alphabet.dat");
if(ifp != null) {
for(cnt = 0; cnt < 26; cnt +=1) {
array[cnt] = (char)ifp.read();
System.out.format("%c", array[cnt]);
}
System.out.print(System.getProperty("line.separator"));
for(cnt = 0; cnt < 10; cnt +=1) {
System.out.format("%c", array[cnt]);
}
System.out.print(System.getProperty("line.separator"));
for(cnt = 20; cnt < 26; cnt += 1) {
System.out.format("%c", array[cnt]);
}
System.out.print(System.getProperty("line.separator"));
System.out.format("%c%s", array[10], System.getProperty("line.separator"));
for(cnt = 26; cnt > -1; cnt -= 1) {
System.out.format("%c", array[cnt]);
}
System.out.print(System.getProperty("line.separator"));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Here is the second one; just slightly different:
import java.io.*;
public class Main {
public static void main(String[] args) {
char[] array = new char[30];
int cnt;
try {
FileReader ifp = new FileReader("alphabet.dat");
if(ifp != null) {
if(ifp.read(array, 0, 26) > 0) {
for(cnt = 0; cnt < 26; cnt +=1) {
System.out.format("%c", array[cnt]);
}
System.out.print(System.getProperty("line.separator"));
for(cnt = 0; cnt < 10; cnt +=1) {
System.out.format("%c", array[cnt]);
}
System.out.print(System.getProperty("line.separator"));
for(cnt = 20; cnt < 26; cnt += 1) {
System.out.format("%c", array[cnt]);
}
System.out.print(System.getProperty("line.separator"));
System.out.format("%c%s", array[10], System.getProperty("line.separator"));
for(cnt = 26; cnt > -1; cnt -= 1) {
System.out.format("%c", array[cnt]);
}
System.out.print(System.getProperty("line.separator"));
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
They both output:
abcdefghijklmnopqrstuvwxyz
abcdefghij
uvwxyz
k
zyxwvutsrqponmlkjihgfedcba
when alphabet.dat is in the same directory as the class file.