Convert decrypted file string to int

So I have a basic encryptor that after it decrypts, I want to convert the string of numbers in that file to an int.

public class Encryption {
	
	//Basic Encryptor/Decryptor
	public Encryption() throws IOException {
		StringBuffer num = new StringBuffer("100");
		encrypt(num);
		
		File f = new File("C:\\fun\\a");
		if(f.mkdirs()) {
		File f2 = new File(f,"b.txt");
		FileWriter fw = new FileWriter(f2);
		BufferedWriter bw = new BufferedWriter(fw);	
		bw.write(num.toString());
		bw.close();
		
		Scanner s = new Scanner(f2);
		String aaa = new String(s.nextLine());
		StringBuffer bbb = new StringBuffer(aaa);
		decrypt(bbb);
		int b = Integer.parseInt(aaa.toString());
		
		System.out.println(b);
		
		
		
		}
		
	}
	
	//ENCRYPTOR
	public static void encrypt(StringBuffer word) {
		for(int i = 0; i < word.length(); i++) {
			int temp = 0;
			temp = (int)word.charAt(i);
			temp = temp * 9;
			word.setCharAt(i, (char)temp);
		}
	}
	
	//DECRYPTOR
	public static void decrypt(StringBuffer word) {
		for(int i = 0; i < word.length(); i++) {
			int temp = 0;
			temp = (int)word.charAt(i);
			temp = temp / 9;
			word.setCharAt(i, (char)temp);
		}
	}
	
	
	public static void main(String[] args) {	
		try {
			@SuppressWarnings("unused")
			Encryption e = new Encryption();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

I tried to convert the string buffer to a string then an int. When I check the file, it is still encrypted and the console has an error decrypting.

Exception in thread "main" java.lang.NumberFormatException: For input string: "???"
	at java.lang.NumberFormatException.forInputString(Unknown Source)
	at java.lang.Integer.parseInt(Unknown Source)
	at java.lang.Integer.parseInt(Unknown Source)
	at Encryptor.Encryption.<init>(Encryption.java:28)
	at Encryptor.Encryption.main(Encryption.java:62)

Which points to

int b = Integer.parseInt(aaa.toString());

.

The thing that’s happening here is that “???” is a entry in your encrypted data. Your parser only accepts numbers. The one below ignores if it isn’t a number, and returns -1.

public int parseInt(String s){
        int out = -1;
        try{
              out = Integer.parseInt(s);
        } catch ( NumberFormatException nfe ) {}
        return out;
}
int b = parseInt(aaa.toString());

Print b out, if it returns -1. Then aaa.toString(); isn’t a number. Else, it’s a number.

What if the string is -1?

In OP’s case, he’s perfectly fine. Chars -> int gives you an ascii code

And ascii’s definition of ints are unsigned: