2 * Copyright 2021 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.holmes.common.utils;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 import java.io.BufferedReader;
23 import java.io.FileNotFoundException;
24 import java.io.FileReader;
25 import java.io.IOException;
27 public class FileUtils {
29 final static private Logger LOGGER = LoggerFactory.getLogger(FileUtils.class);
31 static public String readTextFile(String path) {
33 BufferedReader br = new BufferedReader(new FileReader(path));
34 StringBuilder sb = new StringBuilder();
36 while ((line = br.readLine()) != null) {
40 } catch (FileNotFoundException e) {
41 LOGGER.warn("No file found: {}", path);
42 } catch (IOException e) {
43 LOGGER.error(String.format("Failed to read file contents from '%s'.", path), e);
44 } catch (Exception e) {
45 LOGGER.warn("Unknown exception occurred!", e);