Java InputStream Create getInputStream(String[] args)

Here you can find the source of getInputStream(String[] args)

Description

Searches the command line args for -f path_to_file.

License

LGPL

Parameter

Parameter Description
args command line args given to the program

Return

a or , respectively

Declaration

public static InputStream getInputStream(String[] args) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

public class Main {
    /**/*from  w  ww .  ja va2  s.c  om*/
     * Searches the command line args for -f path_to_file. If it is present, it returns a {@link java.io.FileInputStream}. 
     * @param args command line args given to the program
     * @return a {@link java.io.FileInputStream} or {@link System.in}, respectively
     */
    public static InputStream getInputStream(String[] args) {

        for (int i = 0; i < args.length - 1; i++) {
            if ("-f".equals(args[i])) {
                File f = new File(args[i + 1]);
                if (f.exists() && f.isFile())
                    try {
                        return new FileInputStream(f);
                    } catch (FileNotFoundException e) {
                        System.err.println("Something went horribly wrong!");
                        e.printStackTrace();
                    }
            }
        }

        return System.in;
    }
}

Related

  1. getInputStream(String text)
  2. getInputStream(String thePath)
  3. getInputStream(String url)
  4. getInputStream(String xmlStr)
  5. getInputStream(String... subpaths)
  6. inputStream(final File file)
  7. inputStream(final String in)
  8. inputStream(String fileName)
  9. inputStream(String path)