Here you can find the source of readAll(String ip)
public static List<String> readAll(String ip)
//package com.java2s; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ConcurrentHashMap; public class Main { private static ConcurrentHashMap<String, Object> monitor = new ConcurrentHashMap<String, Object>(); private static String rootPath; private static final String CHARSET = "UTF-8"; public static List<String> readAll(String ip) { if (ip == null) { return null; }/*from w ww .j a v a 2 s .c om*/ BufferedReader br = null; List<String> result = new ArrayList<String>(); File file = null; // Object monitor1 = monitor.putIfAbsent(ip, new Object()); synchronized (monitor) { try { file = new File(createFileNameByIp(ip)); if (!file.exists()) { return null; } br = new BufferedReader(new InputStreamReader(new FileInputStream(file), CHARSET)); String line = null; while ((line = br.readLine()) != null) { if (!"".equals(line)) { result.add(line); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if (br != null) { br.close(); } file.delete(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return result; } private static String createFileNameByIp(String ip) { ip = ip.replace(".", "_"); String filePath = rootPath + File.separator + ip + ".txt"; System.out.println("filePaht:" + filePath); return filePath; } }