Hello ..
I am trying to open an encrypted file, and then pass it to my decryption method to decrypt it and display the text on the screen .. I'm getting a null!

This is my decrypt code:

public String decrypt(String encrypted)
	{
		StringBuilder decryption = new StringBuilder();

		for(int i=0; i< encrypted.length(); i++)
		{
			int pos=0;
			int index, index1;
			index=0;
			index1=0;

			char r= keyWord.charAt( i% keyWord.length());
			char c= encrypted.charAt(i);

			for(int row =0; row<matrix.length ; row++)
			{
				if(matrix[row][0] == r)
				index= row;
			}
			for(pos=0 ; pos< matrix.length ; pos++)
			{
				if(matrix[index][pos] == c)
				index1 =pos;
			}
			decryption.append(matrix[0][index1]);
		}// end for
		System.out.println(decryption.toString());
		return decryption.toString();
	}

This is my openFile method code:

JFileChooser openDialog = new JFileChooser(".");
		int selection = openDialog.showOpenDialog(null);

		if(selection == openDialog.APPROVE_OPTION)
		{
			File selected = openDialog.getSelectedFile();
			Scanner kb= new Scanner(selected);

			String key= kb.next();
			setKey(key);

			String text= kb.nextLine();

		}
			return text;

can anybody see why am I getting a null!

You didn't use setSelectedFile(File) but you use getSelectedFile()??? Then what file are you actually selecting? Here is the JFileChooser API.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.