Following is my code, to read comma delimited integer(Ascii) value from a .txt file, and storing into integer array. And from integer array to integer, for integer to character conversion. So that I can get the corresponding character against the Ascii value which is already stored in comma delimited .txt file. But in my code there is compilation error. Please help me to fulfil my requirements.
import java.io. File;
import java.io. FileNotFoundException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.function.BinaryOperator;
import java.util.*;
public class Read_int_array_a
{
private final static String FILE_NAME = "D:/sumit/sample-project/final/file3.txt";
private final static String DELIMITER = ", ";
public static void main(String[] args)
{
File inputFile = new File(FILE_NAME);
ArrayList<Integer> numbers = new ArrayList<Integer>();
try
{
Scanner scanner = new Scanner(inputFile);
scanner.useDelimiter(DELIMITER);
while(scanner.hasNext())
{
String value = scanner.next();
Integer num = Integer.parseInt(value);
System.out.print(num);
numbers.add(num);
}
scanner.close();
System.out.println(" ");
int[] jcdIntArray = new int[numbers.size()];
int myInt = 0;
for(Integer jcdInt : numbers) {
jcdIntArray[myInt++] = jcdInt;
}
for(Integer myInteger : jcdIntArray) {
char ch = (char)myInteger;
System.out.print(ch);
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
}
Data of file3.txt file is bellow :
70, 73, 78, 65, 78, 67, 73, 65, 76, 32, 80, 82, 79, 68, 85, 67, 84, 83, 32, 68, 73, 83, 84, 82, 73, 66, 85, 84, 73, 79, 78, 32, 76, 73, 77, 73, 84, 69, 68