1 // Copyright 2011 Google Inc. All Rights Reserved.
\r
3 // Licensed under the Apache License, Version 2.0 (the "License");
\r
4 // you may not use this file except in compliance with the License.
\r
5 // You may obtain a copy of the License at
\r
7 // http://www.apache.org/licenses/LICENSE-2.0
\r
9 // Unless required by applicable law or agreed to in writing, software
\r
10 // distributed under the License is distributed on an "AS IS" BASIS,
\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 // See the License for the specific language governing permissions and
\r
13 // limitations under the License.
\r
15 package com.hughes.util;
\r
17 import java.io.BufferedReader;
\r
18 import java.io.File;
\r
19 import java.io.FileInputStream;
\r
20 import java.io.FileOutputStream;
\r
21 import java.io.IOException;
\r
22 import java.io.InputStreamReader;
\r
23 import java.io.PrintStream;
\r
24 import java.io.RandomAccessFile;
\r
25 import java.util.ArrayList;
\r
26 import java.util.List;
\r
28 @SuppressWarnings("WeakerAccess")
\r
29 public final class FileUtil {
\r
30 public static String readLine(final RandomAccessFile file, final long startPos) throws IOException {
\r
31 file.seek(startPos);
\r
32 return file.readLine();
\r
35 public static List<String> readLines(final File file) throws IOException {
\r
36 final List<String> result = new ArrayList<>();
\r
37 try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file)))) {
\r
39 while ((line = in.readLine()) != null) {
\r
46 public static String readToString(final File file) throws IOException {
\r
47 StringBuilder result = new StringBuilder();
\r
48 try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file)))) {
\r
50 while ((line = in.readLine()) != null) {
\r
51 result.append(line).append("\n");
\r
54 return result.toString();
\r
57 public static void writeStringToUTF8File(final String string, final File file) {
\r
58 throw new IllegalStateException();
\r
61 public static void printString(final File file, final String s) throws IOException {
\r
62 final PrintStream out = new PrintStream(new FileOutputStream(file));
\r