用省内存的方式读取大文件

@param path
@return
558875
public static LinkedList<String> readLineListWithLessMemory(String path)
    {
        LinkedList<String> result = new LinkedList<String>();
        String line = null;
        boolean first = true;
        try
        {
            BufferedReader bw = new BufferedReader(new InputStreamReader(IOUtil.newInputStream(path), "UTF-8"));
            while ((line = bw.readLine()) != null)
            {
                if (first)
                {
                    first = false;
                    if (!line.isEmpty() && line.charAt(0) == '\uFEFF')
                        line = line.substring(1);
                }
                result.add(line);
            }
            bw.close();
        }
        catch (Exception e)
        {
            logger.warning("加载" + path + "失败，" + e);
        }

        return result;
    }
915690
public List<String> lsFiles(String path) {
		return ls(path, new Filter<LsEntry>() {
			@Override
			public boolean accept(LsEntry t) {
				return false == t.getAttrs().isDir();
			}
		});
	}
1183132
public static String resolve(String path) {
        if (path == null) {
            return null;
        }
        if (path.startsWith("~" + File.separator)) {
            return SystemUtil.getUserHome() + path.substring(1);
        }
        return path;
    }
232618
public static String readResource(String path) {
        final long start = System.nanoTime();
        try (InputStream is = UScale.class.getClassLoader().getResourceAsStream(path);) {
            int len = 0;
            byte[] buffer = new byte[2048];
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            while ((len = is.read(buffer)) >= 0) {
                baos.write(buffer, 0, len);
            }
            return new String(baos.toByteArray(), StandardCharsets.UTF_8);
        } catch (IOException e) {
            LOGGER.log(Level.WARNING, e, () -> "IOException loading resource " + path);
            throw new IllegalStateException("Unable to read class loaded stream " + path, e);
        } catch (RuntimeException re) {
            LOGGER.log(Level.WARNING, re, () -> "Unexpected exception loading resource " + path);
            throw re;
        } finally {
            LOGGER.fine(() -> String.format("Loaded resource %s in %.3fms", path,
                    (System.nanoTime() - start) / 1000000.0));
        }
    }
957264
protected String getValueOfDE(String path) {
        String ret = null;

        for (ListIterator<SyntaxElement> i = elements.listIterator(); i.hasNext(); ) {
            SyntaxElement e = i.next();
            String ePath = e.getPath();
            if (path.equals(ePath) || path.startsWith(ePath + ".")) {
                ret = e.getValueOfDE(path);
                break;
            }
        }

        return ret;
    }
888576
public JSON readFromFile( String path ) {
      return readFromStream( Thread.currentThread()
            .getContextClassLoader()
            .getResourceAsStream( path ) );
   }
695099
public static String normalizePath(String path)
  {
    if(File.separatorChar == '/') {
      return path.replace('\\', '/');
    }
    return path.replace('/', '\\');
  }
1344246
public static byte[] readBytes(String path)
    {
        try
        {
            if (IOAdapter == null) return readBytesFromFileInputStream(new FileInputStream(path));

            InputStream is = IOAdapter.open(path);
            if (is instanceof FileInputStream)
                return readBytesFromFileInputStream((FileInputStream) is);
            else
                return readBytesFromOtherInputStream(is);
        }
        catch (Exception e)
        {
            logger.warning("读取" + path + "时发生异常" + e);
        }

        return null;
    }
374195
public StringPath get(StringPath path) {
        StringPath newPath = getString(toString(path));
        return addMetadataOf(newPath, path);
    }
1166632
public static ArrayList<File> getFilesInDirectoryTree(String path) {
		File directory = new File(path);
		return getContentsInDirectoryTree(directory, "*", true, false);
	}
1354574
public static String fileNameOf(String path) {
        return path.substring(Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\')) + 1);
    }
778402
private String getStringValue(String path) {

        I_CmsXmlContentValue value = m_content.getValue(path, Locale.ENGLISH);
        if (value == null) {
            return null;
        } else {
            return value.getStringValue(m_cms);
        }
    }
65590
static String canonicalPath(String path) {
        List<String> r = new ArrayList<String>(Arrays.asList(path.split("/+")));
        for (int i=0; i<r.size(); ) {
            if (r.get(i).length()==0 || r.get(i).equals(".")) {
                // empty token occurs for example, "".split("/+") is [""]
                r.remove(i);
            } else
            if (r.get(i).equals("..")) {
                // i==0 means this is a broken URI.
                r.remove(i);
                if (i>0) {
                    r.remove(i-1);
                    i--;
                }
            } else {
                i++;
            }
        }

        StringBuilder buf = new StringBuilder();
        if (path.startsWith("/"))
            buf.append('/');
        boolean first = true;
        for (String token : r) {
            if (!first)     buf.append('/');
            else            first = false;
            buf.append(token);
        }
        // translation: if (path.endsWith("/") && !buf.endsWith("/"))
        if (path.endsWith("/") && (buf.length()==0 || buf.charAt(buf.length()-1)!='/'))
            buf.append('/');
        return buf.toString();
    }
125583
public static String getExtension(String path) {
		int idx = path.lastIndexOf("/"); //$NON-NLS-1$
		String filename = idx == -1 ? path : path.substring(idx+1);
		idx = filename.lastIndexOf("."); //$NON-NLS-1$
		return idx == -1 ? "" : filename.substring(idx+1); //$NON-NLS-1$
	}
365551
public static boolean sortDictionary(String path)
    {
        try
        {
            BufferedReader br = new BufferedReader(new InputStreamReader(IOUtil.newInputStream(path), "UTF-8"));
            TreeMap<String, String> map = new TreeMap<String, String>();
            String line;

            while ((line = br.readLine()) != null)
            {
                String[] param = line.split("\\s");
                map.put(param[0], line);
            }
            br.close();

            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(IOUtil.newOutputStream(path)));
            for (Map.Entry<String, String> entry : map.entrySet())
            {
                bw.write(entry.getValue());
                bw.newLine();
            }
            bw.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return false;
        }

        return true;
    }
368013
public static BufferedWriter asBufferedWriter(Path path) throws IOException {
		Validate.notNull(path, "path is null");
		return Files.newBufferedWriter(path, Charsets.UTF_8);
	}
864261
static boolean loadDat(String path)
    {
        try
        {
            ByteArray byteArray = ByteArray.createByteArray(path + Predefine.BIN_EXT);
            if (byteArray == null) return false;
            int size = byteArray.nextInt();
            CoreDictionary.Attribute[] attributes = new CoreDictionary.Attribute[size];
            final Nature[] natureIndexArray = Nature.values();
            for (int i = 0; i < size; ++i)
            {
                // 第一个是全部频次，第二个是词性个数
                int currentTotalFrequency = byteArray.nextInt();
                int length = byteArray.nextInt();
                attributes[i] = new CoreDictionary.Attribute(length);
                attributes[i].totalFrequency = currentTotalFrequency;
                for (int j = 0; j < length; ++j)
                {
                    attributes[i].nature[j] = natureIndexArray[byteArray.nextInt()];
                    attributes[i].frequency[j] = byteArray.nextInt();
                }
            }
            if (!trie.load(byteArray, attributes) || byteArray.hasMore()) return false;
        }
        catch (Exception e)
        {
            logger.warning("读取失败，问题发生在" + e);
            return false;
        }
        return true;
    }