📄 fileaccess.java
字号:
package com.fileAccess;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
public class FileAccess {
private String path;
public Map readFile() throws NumberFormatException, IOException {
HashMap<String, Integer> hm = new HashMap<String, Integer>();
BufferedReader br = new BufferedReader(new FileReader(path));
String str = null;
while ((str = br.readLine()) != null) {
String sl[] = str.split(" ");
if ((sl[0] != null) && sl[0].equals("a_count:")) {
hm.put(sl[0], Integer.parseInt(sl[1]));
} else if ((sl[0] != null) && sl[0].equals("total_count:")) {
hm.put(sl[0], Integer.parseInt(sl[1]));
}
}
return hm;
}
public FileAccess(String path)
{
this.path=path;
}
public synchronized void writeFile(int a_count,int total_count,String path) throws FileNotFoundException
{
System.out.println("write a="+a_count+" t="+total_count);
PrintWriter pw=new PrintWriter(new FileOutputStream(path),true);
pw.println("a_count: "+a_count);
pw.println("total_count: "+total_count);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -