📄 lfile.java
字号:
package myfile;
import java.io.*;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class LFile {
public static void save(String str){
System.out.print("保存");
JFileChooser chooser = new JFileChooser();
FileWriter fileWriter;
File file;
chooser.setDialogTitle("保存");
chooser.showSaveDialog(null);
file = chooser.getSelectedFile();
try{
fileWriter = new FileWriter(file);
fileWriter.write(str);
fileWriter.close();
}catch(FileNotFoundException e){
System.out.println("FileNotFoundException");
}catch(IOException e){
System.out.println("IOException");
}
}
public static String read(){
System.out.print("读取");
JFileChooser chooser = new JFileChooser();
FileReader fileReader;
File file;
chooser.setDialogTitle("载入");
chooser.showDialog(null,"载入");
file = chooser.getSelectedFile();
String str = "";
try{
fileReader = new FileReader(file);
if(fileReader.read()!=-1){
BufferedReader br = new BufferedReader(fileReader);
str = br.readLine();
}
fileReader.close();
}catch(FileNotFoundException e){
System.out.println("FileNotFoundException");
}catch(IOException e){
System.out.println("IOException");
}
return str;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -