I have a text file that has lines of 1's and 0's. However it's printing gibberish when I want the actual number, I think it is loaded in the array correctly but it's not printing.
10100010
10010010
10110101
11100011
10010100
01010100
10000100
11111111
00010100
Code:
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Encoder {
public static void main(String[] args) {
System.out.println("Please enter file Name: ");
Scanner getInput = new Scanner(System.in);
String fileName = getInput.nextLine();
File file = new File(fileName + ".txt");
FileInputStream fstream = null;
try {
fstream = new FileInputStream(file);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
// print the content to console
System.out.println(strLine);
int[] n1 = new int[8];
for (int i = 0; i < 7; i++) {
System.out.println((strLine.charAt(i)));
n1[i] = strLine.charAt(i + 1);
}
for (int n : n1) {
System.out.println(n + " ");
}
ArrayList al = new ArrayList();
}
in.close();
} catch (Exception e) {// Catch exception if any
System.err.println("Error: " + e.getMessage());
}
System.out.println("Even or Odd");
}
}