In this function, I want to get text in the file then convert it from string to decimal values, by add this text to an array apply some loops and put the result to array of integer. While returning this integer array it gives me an error "cannot find symbol variable integerArray"
int[] inputfile () throws Exception{
BufferedReader br = null;
String sCurrentLine;
String message;
br = new BufferedReader(new FileReader("\input.txt"));
while ((sCurrentLine = br.readLine()) != null) {
message=sCurrentLine.toString();
char[] messageArray=message.toCharArray();
int[] integerArray = new int[messageArray.length];
for(int i=0; i<messageArray.length; i++)
integerArray[i] = (int)messageArray[i];
}
return integerArray;
}
How can I solve it?
Update:
I declared variable integerArray outside the while loop, but it always returns the null value, Is there any possible way to return integerArray as int values? because Arrays.toString(integerArray) returns String representation of that array
int[] inputfile () throws Exception{
BufferedReader br = null;
String sCurrentLine;
String message;
br = new BufferedReader(new FileReader("\\input.txt"));
int[] integerArray = null
while ((sCurrentLine = br.readLine()) != null) {
message=sCurrentLine.toString();
char[] messageArray=message.toCharArray();
int[] integerArray = new int[messageArray.length];
for(int i=0; i<messageArray.length; i++)
integerArray[i] = (int)messageArray[i];
}
return integerArray;