Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.*;

import java.util.Scanner;

public class Main {
    public static String readFile(String pathname) {
        File file = new File(pathname);
        StringBuilder fileContents = new StringBuilder((int) file.length());
        String lineSeparator = System.getProperty("line.separator");

        try {
            try (Scanner scanner = new Scanner(file)) {
                while (scanner.hasNextLine()) {
                    fileContents.append(scanner.nextLine()).append(lineSeparator);
                }
                return fileContents.toString();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return "";
    }
}