急救:有关FileChooser类的一个问题!!!!!!!!!!!! JFileChooser.setSelectedFile("test.txt"); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 sorry:JFileChooser.setSelectedFile(new File("test.txt")); 还是不行啊文本框中还是什么都没有啊下面是一段代码saveButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String msg; int result = fDialog.showSaveDialog(frame); if(result == JFileChooser.APPROVE_OPTION){ //显示的文本方法如下: fDialog.setSelectedFile(new File("test.txt")); String fname = fDialog.getName(fDialog.getSelectedFile()); File file = new File(fname); //fDialog.setSelectedFile(file); path = fDialog.getCurrentDirectory(); //fDialog.setApproveButtonToolTipText("yes"); fDialog.setDialogTitle("yes"); String title = fDialog.getApproveButtonText(); //String title = fDialog.getDialogTitle(); //fDialog.setControlButtonsAreShown(false); //System.out.println(title); //file = new File(fname); try{ //file =new File(path+fname); String absolutePath = path.getAbsolutePath(); int length = absolutePath.length(); int c = length - 1; //String test = absolutePath.subString(1,3); if(absolutePath.substring(length - 1 ).equals("\\")) System.out.println(absolutePath + fname); else System.out.println(absolutePath + "\\" + fname); FileOutputStream fout = new FileOutputStream(path+fname); BufferedOutputStream bout= new BufferedOutputStream(fout); DataOutputStream dout = new DataOutputStream(bout); //dout.writeInt(dataSize); //for(int i = 0; i<dataSize; i++){ dout.writeChars("gen.nextDouble()"); //} dout.flush(); fout.close(); System.out.println(dout.size() + "bytes written"); } catch (IOException ee) { } 着急需要知道,帮帮帮忙 请问如何用java获取系统命令参数。 帮忙看看为什么运行TestRun会报空指针错误 javamail收邮件,乱码问题... 《java数据结构和算法》这本书有没有对应的视频? 关于jxta在jBuilder中运行的问题,高分!! 怎么使窗口置顶? 请问大家到底刚如何去学习java? weblogic连sql数据库出错 面象对象的苦恼! 哪位高手讲讲jre,j2se,jdk,j2ee,j2me,java VM等等术语的区别? 怎样最方便地把resultset中的第一个字段取出放在String[]中?
JFileChooser.setSelectedFile(new File("test.txt"));
文本框中还是什么都没有啊
下面是一段代码
saveButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String msg;
int result = fDialog.showSaveDialog(frame);
if(result == JFileChooser.APPROVE_OPTION){
//显示的文本方法如下:
fDialog.setSelectedFile(new File("test.txt"));
String fname = fDialog.getName(fDialog.getSelectedFile());
File file = new File(fname);
//fDialog.setSelectedFile(file);
path = fDialog.getCurrentDirectory();
//fDialog.setApproveButtonToolTipText("yes");
fDialog.setDialogTitle("yes");
String title = fDialog.getApproveButtonText();
//String title = fDialog.getDialogTitle();
//fDialog.setControlButtonsAreShown(false);
//System.out.println(title);
//file = new File(fname);
try{
//file =new File(path+fname);
String absolutePath = path.getAbsolutePath();
int length = absolutePath.length();
int c = length - 1;
//String test = absolutePath.subString(1,3);
if(absolutePath.substring(length - 1 ).equals("\\"))
System.out.println(absolutePath + fname);
else
System.out.println(absolutePath + "\\" + fname);
FileOutputStream fout = new FileOutputStream(path+fname);
BufferedOutputStream bout= new BufferedOutputStream(fout);
DataOutputStream dout = new DataOutputStream(bout);
//dout.writeInt(dataSize);
//for(int i = 0; i<dataSize; i++){
dout.writeChars("gen.nextDouble()");
//}
dout.flush();
fout.close();
System.out.println(dout.size() + "bytes written");
}
catch (IOException ee)
{
}