List of utility methods to do FileInputStream Read
void | readFile(String path, String root, OutputStream out) Dump the contents of the given path (relative to the root) to the output stream. File rootDir = new File(root); while (path.startsWith("/") && (path.length() > 0)) path = path.substring(1); if (path.length() <= 0) throw new FileNotFoundException("Not serving up the root dir"); File target = new File(rootDir, path); if (!target.exists()) throw new FileNotFoundException("Requested file does not exist: " + path); ... |
String | readFile(String pPathToFile) Read a file and return the content. StringBuffer out = new StringBuffer(); FileInputStream inputStrem = new FileInputStream(new File(pPathToFile)); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte buf[] = new byte[1024]; int len; while ((len = inputStrem.read(buf)) > 0) { outStream.write(buf, 0, len); out.append(outStream.toString()); ... |
String | readFile(String resource) read File FileInputStream in = new FileInputStream(resource); if (in == null) { throw new FileNotFoundException(resource); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; while ((len = in.read(buffer)) > 0) { ... |
StringBuffer | readFile(String sFileName) Legge un file int nI = 0; byte buf[] = new byte[4096]; StringBuffer sHold = new StringBuffer(); BufferedInputStream bfin = null; try { bfin = new BufferedInputStream(new FileInputStream(sFileName)); while ((nI = bfin.read(buf)) != -1) { if (nI != -1) ... |
String | readFileAsBinary(File file) read File As Binary StringBuffer stringBuffer = new StringBuffer(); BufferedInputStream input = null; try { input = new BufferedInputStream(new FileInputStream(file)); int read = 0; byte[] buffer = new byte[1024]; while ((read = input.read(buffer)) != -1) stringBuffer.append(read); ... |
FileInputStream | readFileAsInputStream(File file) Read a file as FileInputStream. try { return new FileInputStream(file); } catch (FileNotFoundException e) { return null; |
InputStream | readFileAsInputStream(String fileName) Reads the file corresponding to the passed file name. if (fileName == null) throw new IllegalArgumentException("No file name specified."); File f = new File(fileName); FileInputStream input = null; try { input = new FileInputStream(f); return new BufferedInputStream(input); } catch (Exception e) { ... |
Properties | readFileAsProperties(File file) Uses the contents of a file to populate a Properties object.
Properties properties = new Properties(); properties.load(new FileInputStream(file)); return properties; |
InputStream | readFileAsResource(String fileName) read File As Resource InputStream f; try { FileInputStream fis = new FileInputStream(fileName); f = fis; } catch (FileNotFoundException ex) { f = new Object() { }.getClass().getEnclosingClass().getClassLoader().getResourceAsStream(fileName); if (f == null) { throw new IOException("Cannot load file " + fileName); return f; |
String | ReadFileAsUtf8String(String filePath) Read File As Utf String final File file = new File(filePath); final long fileLength = file.length(); if (fileLength > Integer.MAX_VALUE) { throw new IOException(filePath + " size is too large: " + fileLength); final byte[] buffer = new byte[(int) fileLength]; final FileInputStream istream = new FileInputStream(file); try { ... |