Advertisement
Hi everyone, I wonder if someone can help me with this problem. I create a folder, and would like to save files inside this folder. Could someone tell me which argument to utilise for this purpose, Many thanks.1. This one does the creation /**
*
*/
fileChooser = new JFileChooser ();
cwd = fileChooser.getCurrentDirectory ();
if ( cwd !=null )
{
new_Dir = new File ( cwd, "RSA_KeyPair" );
new_Dir.mkdir ();
}
/**
*
*/
performedSaveFiles ( userName, priv_Key, pub_Key );
2. That one does the saving /*
*
*/
private void performedSaveFiles ( String passed_Name,
String passed_PrivKey,
String passed_PubKey )
{
/**
* Returns the selected file.
* @param name
*/
File name = new File ( passed_Name );
try {
/**
*
*/
currentDir = new File ( "C:\\Documents and Settings\\Collin Galagher\\My Documents\\RSA_KeyPair" );
Were the Problem Start
/**There is the Troubled case...:=)**/
fileChooser.setCurrentDirectory ( currentDir );
if ( currentDir !=null )
{
/**
* Constructs a FileWriter object given a File object.
* @param fileWriter_PrivKey
* @param name - a File object to write to.
*/
FileWriter fileWriter_PrivKey = new FileWriter ( name+".privKey" );
fileWriter_PrivKey.write ( priv_Key );
/**
*
* @param fileWriter_PubKey -
*/
FileWriter fileWriter_PubKey = new FileWriter ( name+".pubKey" );
fileWriter_PubKey.write ( pub_Key );
/**
* @param close (). Close the stream.
*/
fileWriter_PrivKey.close ();
fileWriter_PubKey.close ();
}
/**
* Setup the Hint bar
* @param hintBar
*/
RSA_Demo.hintBar.setText ( " The Files: " +name+".PrivKey and " +name+".PubKey are now saved " );
} catch ( FileNotFoundException fnfex ) {
/**
* Returns the default toolkit.
* param beep ()
*/
Toolkit.getDefaultToolkit ().beep ();
JOptionPane.showMessageDialog ( null,
" File does not Exist" +
" Message is: [" + fnfex.getMessage () +"]" ,
" Invalid File Name" ,
JOptionPane.ERROR_MESSAGE );
} catch ( IOException ioex ) {
/**
* Returns the default toolkit.
* param beep ()
*/
Toolkit.getDefaultToolkit ().beep ();
JOptionPane.showMessageDialog ( null,
" This File cannot be Write" +
" Message is: [" + ioex.getMessage () +"]" ,
" File Cannot be Write" ,
JOptionPane.ERROR_MESSAGE );
}
} // End for Method performedSaveFiles