Java BufferedReader Read loadCredentials(File credentials)

Here you can find the source of loadCredentials(File credentials)

Description

Return the credentials in the file.

License

Open Source License

Parameter

Parameter Description
credentials Credentials file

Return

Credentials

Declaration

public static String[] loadCredentials(File credentials) 

Method Source Code


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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Main {
    /**/*from www  .  j a v  a  2  s.  c  om*/
     * Return the credentials in the file.
     * <ul>
     * <li>First line: user</li>
     * <li>Second line: plain password</li>
     * <li>Third line: token</li>
     * </ul>
     * 
     * @param credentials
     *            Credentials file
     * @return Credentials
     */
    public static String[] loadCredentials(File credentials) {
        BufferedReader reader = null;
        String login = null;
        String password = null;
        String token = null;
        try {
            reader = new BufferedReader(new FileReader(credentials));
            login = readLine(reader);
            password = readLine(reader);
            token = readLine(reader);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return new String[] { login, password, token };
    }

    /**
     * Read a line from the reader
     * 
     * @param reader
     *            Reader
     * @return line from the reader
     * @throws IOException
     */
    private static String readLine(BufferedReader reader) throws IOException {
        String line = reader.readLine();
        if (line != null) {
            return line.trim();
        }
        return null;
    }
}

Related

  1. loadCommonMisspellingsFile(String commonMisspellingsFileLocation)
  2. loadConfFile(String filename, String key)
  3. loadConfig(File conf)
  4. loadConfigProps(String configFile)
  5. loadContents(File file)
  6. loadCsvFile(String fileWithPath, String delimiter)
  7. loadDataURLs(File f, Pattern p)
  8. loadDict(InputStream io, boolean case_sensitive)
  9. loadEnrichmentHits(File file)