lfile.java
来自「java编写的一个网络象棋,通过对方ip连接,开始游戏,同时可以进行聊天,聊天部」· Java 代码 · 共 60 行
JAVA
60 行
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 + =
减小字号Ctrl + -
显示快捷键?