Here you can find the source of loadText(String path)
Parameter | Description |
---|---|
path | path to file or resource |
Parameter | Description |
---|
public static String loadText(String path) throws IOException
//package com.java2s; /*/*from w w w.ja v a2s . c o m*/ * #%L * MiscUtil.java - method51 - University of Sussex - 2,013 * %% * Copyright (C) 2013 - 2014 University of Sussex * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Main { /** * Reads a whole text file into a String. * * @param path path to file or resource * @return contents of the file * @throws java.io.IOException */ public static String loadText(String path) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(path)); String line; StringBuilder text = new StringBuilder(); while ((line = reader.readLine()) != null) { text.append(line); text.append("\n"); } return text.toString(); } }