Saturday, December 29, 2007

to read a file

public static InputStream readFile(String completePathFile)
            throws IOException {
        try {
            File file = new File(completePathFile);
            if (file.exists()) {
                InputStream in = new FileInputStream(file);
                // byte myBytes[] = new byte[in.available()];
                // in.read(myBytes);
                // return new String(myBytes);
                return in;
            } else {
                throw new IOException("FILE TO READ NOT FOUND !! pathFile : "
                        + file.getAbsolutePath());
            }
        } catch (IOException ex) {
            throw new IOException("Error in reading file");
        }
    }

No comments: