Java Path File Read nio readSheBang(Path script)

Here you can find the source of readSheBang(Path script)

Description

read She Bang

License

Open Source License

Declaration

public static String readSheBang(Path script) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.nio.file.Files;
import java.nio.file.Path;

public class Main {
    public static String readSheBang(Path script) throws IOException {
        try (BufferedReader reader = new BufferedReader(
                new InputStreamReader(Files.newInputStream(script), "UTF-8"))) {
            String line = reader.readLine();
            while (line != null) {
                line = line.trim();//from   www  . j ava2  s  .c om
                if (line.length() > 0) {
                    if (line.startsWith("#!")) {
                        return line;
                    } else {
                        // Not found return a default value
                        return "#!/bin/sh";
                    }
                }
                line = reader.readLine();
            }
            // Not found return a default value
            return "#!/bin/sh";
        }
    }
}

Related

  1. readLinesOfFile(String path)
  2. readLineSP(String filePath, int line, int pos)
  3. readLinesToString(Path file)
  4. readManifest(Path path)
  5. readPropertiesFile(Path path)
  6. readStringFromPath(Path path)
  7. readTextFile(Path p)
  8. readTextFileFromResources(String filepath, ClassLoader classLoader)
  9. readTextFromFile(String textFilePath)