このコードを使用してMysqlからデスクトップにPDFファイルを保存しますが、ファイルは拡張子なしで保存されます。拡張子pdfを使用して自動的に保存するにはどうすればよいですか?!!
JFileChooser JFileChooser = new JFileChooser(".");
Activiter ac = new Activiter();
int status = JFileChooser.showDialog(null,"Saisir l'emplacement et le nom du fichier cible");
if(status == JFileChooser.APPROVE_OPTION)
{
try
{
ac.chargeIMG(jTable3.getValueAt(rec, 6).toString(),JFileChooser.getSelectedFile().getAbsolutePath());
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,"Une erreur s'est produite dans le chargement de documents.");
ex.printStackTrace();
}
}
ヘルプをありがとう、ac.chargeIMGによって照合されたmethodechargerIMG
ChargeIMGはMySQLからpdfファイルを提供します。コードは
public void chargeIMG(String idpro, String location) throws Exception
{
// cnx
File monImage = new File(location);
FileOutputStream ostreamImage = new FileOutputStream(monImage);
try {
PreparedStatement ps = conn.prepareStatement("SELECT img FROM projet WHERE idpro=?");
try
{
ps.setString(1,idpro);
ResultSet rs = ps.executeQuery();
try
{
if(rs.next())
{
InputStream istreamImage = rs.getBinaryStream("img");
byte[] buffer = new byte[1024];
int length = 0;
while((length = istreamImage.read(buffer)) != -1)
{
ostreamImage.write(buffer, 0, length);
}
}
}
finally
{
rs.close();
}
}
finally
{
ps.close();
}
}
finally
{
ostreamImage.close();
}
}