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 was compilation error. Which already solved by your valuable suggestion. I am very much thankful to you.
But presently I am facing another problem, when I am trying to store the corresponding character in to .pdf file. I made some alteration in to the code, but it is giving compilation error. Please help me to fulfil my requirements. So that I can print the corresponding character against the Ascii value into a .pdf file.
import java.io.File;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.function.BinaryOperator;
import java.util.*;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
public class write_ascii_in_pdf {
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>();
Document document = new Document();
try
{
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("write_ascii_in_pdf.pdf"));
Scanner scanner = new Scanner(inputFile);
scanner.useDelimiter(DELIMITER);
while(scanner.hasNext())
{
String value = scanner.next();
Integer num = Integer.parseInt(value);
numbers.add(num);
}
scanner.close();
int[] jcdIntArray = new int[numbers.size()];
int myInt = 0;
for(Integer jcdInt : numbers) {
jcdIntArray[myInt++] = jcdInt;
}
document.open();
for(int myInteger : jcdIntArray) {
char ch = (char)myInteger;
document.add(ch);
}
document.close();
writer.close();
}
catch (DocumentException e)
{
e.printStackTrace();
}
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