Java URL Load readFromFile(URL fileName)

Here you can find the source of readFromFile(URL fileName)

Description

read From File

License

Open Source License

Declaration

public static String readFromFile(URL fileName) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2005-2011 eBay Inc./*from ww w.ja  va  2s. com*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 *******************************************************************************/

import java.io.InputStreamReader;

import java.net.URL;

public class Main {
    public static String readFromFile(URL fileName) {

        try {
            final StringBuffer sb = new StringBuffer();
            final char buf[] = new char[4096];
            int numRead;
            final InputStreamReader isr = new InputStreamReader(fileName.openStream(), "utf-8");

            do {
                numRead = isr.read(buf, 0, buf.length);
                if (numRead > 0)
                    sb.append(buf, 0, numRead);
            } while (numRead >= 0);

            isr.close();

            return sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. readFileContent(URL file)
  2. readFileFromURL(URL url)
  3. readFileIntoMap(URL url)
  4. readFileIntoString(URL input)
  5. readFileIntoString(URL url)
  6. readFromFile(URL source)
  7. readFromUrl(String url)
  8. readFromUrl(String urlString)
  9. readFromUrl(String urlText)