List of usage examples for java.io FileInputStream close
public void close() throws IOException
From source file:TestDB.java
/** * Gets a connection from the properties specified in the file database.properties * @return the database connection// w w w . j av a2 s. co m */ public static Connection getConnection() throws SQLException, IOException { Properties props = new Properties(); FileInputStream in = new FileInputStream("database.properties"); props.load(in); in.close(); String drivers = props.getProperty("jdbc.drivers"); if (drivers != null) System.setProperty("jdbc.drivers", drivers); String url = props.getProperty("jdbc.url"); String username = props.getProperty("jdbc.username"); String password = props.getProperty("jdbc.password"); return DriverManager.getConnection(url, username, password); }
From source file:Main.java
public static String getStringFromFile(String filePath) throws Exception { File fl = new File(filePath); FileInputStream fin = new FileInputStream(fl); String ret = convertStreamToString(fin); fin.close(); return ret;/*from w w w. j av a 2s. com*/ }
From source file:Main.java
public static String readFromFile(String path) { String str = null;//from w w w . j ava2s.co m if (path == null || path.trim().length() == 0) { return null; } File file = new File(path); if (file.exists() && file.isFile()) { int filelength = (int) file.length(); byte[] filecontent = new byte[filelength]; try { FileInputStream in = new FileInputStream(file); in.read(filecontent); in.close(); str = new String(filecontent, "UTF-8"); } catch (Exception e) { Log.v(TAG, "read file is error"); return null; } } return str; }
From source file:Main.java
public static void playRecordAction(File audiofile) throws Exception { MediaPlayer mp = new MediaPlayer(); FileInputStream fis = new FileInputStream(audiofile.getAbsolutePath()); mp.setDataSource(fis.getFD());//from w w w. ja v a 2 s. c om mp.prepare(); fis.close(); mp.start(); }
From source file:Main.java
public static boolean isWAVFile(String fileName) { byte header[] = new byte[16]; try {/* ww w. ja v a2s . co m*/ File f = new File(fileName); if (!f.exists()) { Log.d("OpusTool", fileName + ":" + "File does not exist."); return false; } long actualLength = f.length(); FileInputStream io = new FileInputStream(f); io.read(header, 0, 16); io.close(); String tag = new String(header, 0, 4) + new String(header, 8, 8); if (!tag.equals("RIFFWAVEfmt ")) { Log.d("OpusTool", fileName + ":" + "It's not a WAV file!"); return false; } long paraLength = (header[4] & 0x000000ff) | ((header[5] << 8) & 0x0000ff00) | ((header[6] << 16) & 0x00ff0000) | ((header[7] << 24) & 0xff000000); if (paraLength != actualLength - 8) { Log.d("OpusTool", fileName + ":" + "It might be a WAV file, but it's corrupted!"); return false; } return true; } catch (Exception e) { Log.d("OpusTool", fileName + ":" + "File Error"); return false; } }
From source file:Main.java
public static Bitmap load(String filepath) { Bitmap bitmap = null;/*from w ww . java 2s. c o m*/ try { FileInputStream fin = new FileInputStream(filepath); bitmap = BitmapFactory.decodeStream(fin); fin.close(); } catch (FileNotFoundException e) { } catch (IOException e) { } return bitmap; }
From source file:Main.java
public static String convertXmlToString(String xmlFileName) throws Exception { File file = new File(xmlFileName); FileInputStream insr = new FileInputStream(file); byte[] fileBuffer = new byte[(int) file.length()]; insr.read(fileBuffer);/*from www . j a v a 2s.c o m*/ insr.close(); return new String(fileBuffer); }
From source file:Main.java
public static synchronized Element getRootElement(String fileName) { if (fileName == null || fileName.length() == 0) { return null; }/*from ww w . jav a 2 s . co m*/ try { Element rootElement = null; FileInputStream fis = new FileInputStream(fileName); rootElement = getRootElement(fis); fis.close(); return rootElement; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String getBuildProp(String propertyName) { Properties buildProps = new Properties(); try {/*w w w . j a va 2 s . c o m*/ FileInputStream is = new FileInputStream(new File(BUILD_PROP)); buildProps.load(is); is.close(); return buildProps.getProperty(propertyName, ""); } catch (IOException e) { logError(e); } return ""; }
From source file:Main.java
public static byte[] readFile(File f) throws IOException { FileInputStream fis = new FileInputStream(f); try {/* w w w. ja va2s. c o m*/ return readBytes(fis); } finally { fis.close(); } }