JFileChooser fc = new JFileChooser("C:/");
fc.setMultiSelectionEnabled(true);
if(fc.showOpenDialog(null)!= JFileChooser.APPROVE_OPTION) {
File[] files = fc.getSelectedFiles();
System.out.print("size="+files.length);
// :-) :-) :-)
}
fc.setMultiSelectionEnabled(true);
if(fc.showOpenDialog(null)!= JFileChooser.APPROVE_OPTION) {
File[] files = fc.getSelectedFiles();
System.out.print("size="+files.length);
// :-) :-) :-)
}
解决方案 »
- 以前没注意,不干预程序的运行,今天发现控制台有个这样的警告出现了。
- 请帮忙看一下这道SWING题!
- 怎么用任务计划扫描java控制台程序是否运行
- java中有垃圾回收GC, 为什么还要调用close
- 请问接口里的内部类是否默认就是public static final的?
- JAVA 求助
- java中一个float对象占多大内存空间?
- java多线程聊天,两个客户端通过服务端转发消息实现通信,可是为什么信息发不出去,?以下客户端和服务端
- 我想知道 一个 RMI 服务器能同时连接多少个客户端?马上给分
- 请问现在写java程序用什么?UltraEdit还是别的什么?
- 关于Eclipse中文网站方案征集!
- 执行insert into 时显示科学计数法是怎么回事?
chooser.setMultiSelectionEnabled(false);
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
File file;
String addr = "";
if( chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION ) {
file = chooser.getSelectedFile();
fc.setMultiSelectionEnabled(true);
System.out.print("hello0");
if(fc.showOpenDialog(null)!= JFileChooser.APPROVE_OPTION) {
System.out.print("hello1");
File[] files = fc.getSelectedFiles();
System.out.print("hello2");
System.out.print("size="+files.length);
// :-) :-) :-)
}hello1,hello2都打印不出来。
this.strSelectedPreAddr
是什么类型的变量?初始值是什么?
String filename = new String();
if(returnVal == JFileChooser.APPROVE_OPTION)
{
try
{
filename = jFileChooser1.getSelectedFile().getAbsolutePath();
this.setTitle("OPEN"+filename);
jEditorPane1.setText(this.readfile(filename));
}catch(Exception ie){}
}
~~~~~~~~
这里this就是说是我这个类的一个属性,str说明他是字符串,我的习惯,呵呵。
兄台的习惯很好啊。
不过,你给的代码和helpall() 的都是不能返回路径文件名。 heyday(水中天) 这位兄台的就可以。不知道为什么。
设定选择模式chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);就是只能选目录。另外提供文本域来让用户输入文件名,我在最上面就说过了。新建只能这么做,如果已有就和导出一样了。
导出我还是没弄出来。
现在的问题是:我输入一个文件名,不知道如何在该目录下一输入的名字为文件名来新建这个文本文件。如果输入的文件在该目录下已经存在,我想把它覆盖掉。bluesmile979(笑着) 老兄,帮帮忙吧。
String readline = "";
try{
RandomAccessFile openfile = new RandomAccessFile( this.OpenPathFileName,"r" );
File file = new File( this.SavePathFileName + "temp" );
System.out.println("保存アドレス" + this.SavePathFileName );
RandomAccessFile savefile = new RandomAccessFile( file,"rw" ); readline = openfile.readLine();
while( true ) {
if( readline != null ) {
System.out.println( readline );
if( readline != null ) {
savefile.writeBytes( this.StringHandle( readline ) );
savefile.writeBytes("\n");
}
readline = openfile.readLine();
} else {
savefile.close();
openfile.close();
break;
}
}
File filesource = new File( this.SavePathFileName );
if( filesource.exists() == true ) {
filesource.delete();
}
file.renameTo( new File( this.SavePathFileName ) );
}catch( FileNotFoundException ee ) {
System.out.println(ee.getMessage());
}catch( IOException e ) {
System.out.println(e.getMessage());
}
}
我想用JFileChooser选择一个目录,然后输入一个文件名。
根据这个文件名在该目录下建一个新的空的文本文件。然后在从数据库里面取出数据按照一定的格式写到这里面去。
String strSelectedPreAddr = System.getProperty( "user.dir" );
JFileChooser chooser = new JFileChooser( strSelectedPreAddr);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
File file;
if( chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION ) {
file = chooser.getSelectedFile();
String strTemp=file.toString();
System.out.println("****filename****"+file.toString());
File fl=new File(strTemp);
}
运行后可以得到"****filename****"d:\jdbc\test.txt
但是这样File fl=new File(strTemp);并不能在jdbc该目录下建了test.txt文件。我写的明白么?
file.createNewFile();
}
谢谢,这正是我想得到的。
你真是高手。以后有什么不会的还的请教你啊。
我的QQ是4951224。请加我。