JFileChooserã§ãã¡ã¤ã«ãä¿åããã¨ãã
ã¦ã¼ã¶ãèªåã§æ¡å¼µåãæ¸ãã¦ãï¼æ¢åã®æ¡å¼µåã®ãã¡ã¤ã«ãä¸æ¸ããããã¨ãã¦ãï¼
ã¦ã¼ã¶ããã¡ã¤ã«åã ããæ¸ãã¦ããåãçµæã«ãããã£ãã®ã§ãããæ¹ã¡ã¢ã
ï¼ä¾ãã°ãmemoãã¨æ¸ãã¦ããmemo.txtãã¨æ¸ãã¦ãã
ãmemo.txtãã¨ä¿åãããããã«ãããããã§ããï¼
Chooserã«å ¥åããããã¡ã¤ã«ã®ã¤ã³ã¹ã¿ã³ã¹ãfileã¨ããã¨
PrintWriter pw = new PrintWriter(file + ".dat");
ã¨ããã°ãæ¡å¼µåã«ã.txtããå ¥åãããã
ãã¨ã¯substring()ã¡ã½ããã使ã£ã¦ãæ«å°¾ï¼æåãã.txtããã©ããããã§ãã¯ããå ´ååãã
ã¾ã¨ããã¨ä»¥ä¸ã®ã¨ããã
ãªãããã£ã¨æ¥½ã«ããæ¹æ³ãããããã
ããã©ãã®æ¹æ³ãå¥ã«ç ©éã§ã¯ãªãã®ã§ãã¨ããããã¯ããã§è¯ãã¨ãã¾ãã
JFileChooser fc = new JFileChooser();
FileNameExtensionFilter ff = new FileNameExtensionFilter("ããã¹ããã¡ã¤ã«", "txt");
fc.setFileFilter(ff);
int retval = fc.showSaveDialog(this);
if (retval != JFileChooser.APPROVE_OPTION) {
return;
}
File file = fc.getSelectedFile();
try {
PrintWriter pw;
if (file.toString().substring(file.toString().length() - 4).equals(".txt")) {
pw = new PrintWriter(file);
} else {
pw = new PrintWriter(file + ".txt");
}
pw.println("ã¦ãã¨");
pw.close();
}catch(IOException e){
}
ã¦ã¼ã¶ãèªåã§æ¡å¼µåãæ¸ãã¦ãï¼æ¢åã®æ¡å¼µåã®ãã¡ã¤ã«ãä¸æ¸ããããã¨ãã¦ãï¼
ã¦ã¼ã¶ããã¡ã¤ã«åã ããæ¸ãã¦ããåãçµæã«ãããã£ãã®ã§ãããæ¹ã¡ã¢ã
ï¼ä¾ãã°ãmemoãã¨æ¸ãã¦ããmemo.txtãã¨æ¸ãã¦ãã
ãmemo.txtãã¨ä¿åãããããã«ãããããã§ããï¼
Chooserã«å ¥åããããã¡ã¤ã«ã®ã¤ã³ã¹ã¿ã³ã¹ãfileã¨ããã¨
PrintWriter pw = new PrintWriter(file + ".dat");
ã¨ããã°ãæ¡å¼µåã«ã.txtããå ¥åãããã
ãã¨ã¯substring()ã¡ã½ããã使ã£ã¦ãæ«å°¾ï¼æåãã.txtããã©ããããã§ãã¯ããå ´ååãã
ã¾ã¨ããã¨ä»¥ä¸ã®ã¨ããã
ãªãããã£ã¨æ¥½ã«ããæ¹æ³ãããããã
ããã©ãã®æ¹æ³ãå¥ã«ç ©éã§ã¯ãªãã®ã§ãã¨ããããã¯ããã§è¯ãã¨ãã¾ãã
JFileChooser fc = new JFileChooser();
FileNameExtensionFilter ff = new FileNameExtensionFilter("ããã¹ããã¡ã¤ã«", "txt");
fc.setFileFilter(ff);
int retval = fc.showSaveDialog(this);
if (retval != JFileChooser.APPROVE_OPTION) {
return;
}
File file = fc.getSelectedFile();
try {
PrintWriter pw;
if (file.toString().substring(file.toString().length() - 4).equals(".txt")) {
pw = new PrintWriter(file);
} else {
pw = new PrintWriter(file + ".txt");
}
pw.println("ã¦ãã¨");
pw.close();
}catch(IOException e){
}