如何用双反斜杠“\”或单斜杠“/”替换字符串文件路径中的单个反斜杠“\”?我需要它,以便我可以正确执行java中的桌面方法
这是代码:
JButton btnAdd = new JButton("Add");
btnAdd.setBounds(101, 560, 89, 23);
frmAddContract.getContentPane().add(btnAdd);
btnAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try{
String cntr = ContractNo.getText();
String en = EngagerName.getText();
String cont = contNo.getText();
String mo = month.getText();
String d = day.getText();
String yr = year.getText();
String dte = yr + "-" + mo + "-" + d;
String cla = cladd.getText();
String tm = tme.getText() + ":00";
String evadd = eventadd.getText();
String filepath = textField_fp.getText();
String ref = refer.getText();
String SQL = "insert into cis "+
"values ('"+cntr+"','"+en+"','"+
cont+"','"+cla+"','"+dte+"','"+tm+"','"+
evadd+"','"+filepath+"','"+ref+"');";
PreparedStatement stmt = conn.prepareStatement(SQL);
stmt.executeUpdate();
JOptionPane.showMessageDialog(null, "Addition of Contract Successful!");
frmAddContract.setVisible(false);
PreparedStatement show = conn.prepareStatement("select * from kusinanikambal.cis;");
ResultSet rs = show.executeQuery();
System.out.println(rs.getRowId("engager"));
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
});
答案 0 :(得分:0)
String filepath = textField_fp.getText().replaceAll("\\\\","\\\\\\\\");