Java BufferedReader Read loadSqlFile(String path)

Here you can find the source of loadSqlFile(String path)

Description

This method return the sql scripts from the given sql file.

License

Open Source License

Parameter

Parameter Description
path the path of the sql file

Exception

Parameter Description
IOException if fails to read the sql file

Return

the sql scripts

Declaration

private static String[] loadSqlFile(String path) throws IOException 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;

import java.io.FileReader;
import java.io.IOException;

public class Main {
    /**// w  w w. java 2 s . c  om
     * <p>
     * This method return the sql scripts from the given sql file.
     * </p>
     *
     * @param path the path of the sql file
     * @return the sql scripts
     *
     * @throws IOException if fails to read the sql file
     */
    private static String[] loadSqlFile(String path) throws IOException {
        StringBuffer sb = new StringBuffer();
        BufferedReader reader = new BufferedReader(new FileReader(path));
        try {
            String line = reader.readLine();
            while (line != null) {
                line = line.trim();
                if (line.length() != 0 && !line.startsWith("--")) {
                    sb.append(line);
                }

                line = reader.readLine();
            }

            return sb.toString().split(";");
        } finally {
            reader.close();
        }
    }
}

Related

  1. loadReaderFromClasspath(Class c, String filename)
  2. loadReaderToList(Reader reader)
  3. loadRealDataGraphFromEmbers(String fileName, String splitter)
  4. loadSentences(InputStream stream, List jsonSentences)
  5. loadSimpleTextFile(File file, int bufferSize)
  6. loadSQLFromFile(String fileName)
  7. loadStream(InputStream is)
  8. loadStreamContent(InputStream stream)
  9. loadSystemClassPath()