📄 file_io.java
字号:
package project;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
public class File_IO {
public void saveFile(String fileName, String text) throws IOException {
BufferedWriter out = new BufferedWriter(new FileWriter(fileName));
out.write(text);
out.close();
}
public ArrayList<String> openFile(String filename) {
RandomAccessFile in = null;
try {
in = new RandomAccessFile(filename, "r");
} catch (FileNotFoundException e) {
System.out.println(e.toString());
System.out.println(" No found the file you want!");
System.exit(0);
}
String s1;
s1 = "";
ArrayList<String> data = new ArrayList<String>();
try {
while ((s1 = in.readLine()) != null) {
data.add(s1);
}
} catch (IOException e) {
System.out.println(e.toString());
System.out.println("IO Error!");
System.exit(0);
}
return data;
}
public int[] StringToInteger(char[] token, String str) {
ArrayList<String> tstr = new ArrayList<String>();
char[] ch = new char[str.length()];
ch = str.toCharArray();
int marker = 0;
int postion = 0;
for (int i = 0; i < str.length(); i++) {
for (int j = 0; j < token.length; j++) {
if (ch[i] == token[j]) {
tstr.add(str.substring(marker, i));
marker = i + 1;
postion++;
}
}
}
tstr.add(str.substring(marker, str.length()));
tstr.remove("");
int[] p = new int[tstr.size()];
for (int i = 0; i < p.length; i++) {
p[i] = Integer.parseInt((String) tstr.get(i));
}
return p;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -