List of usage examples for java.io FileReader read
public int read(java.nio.CharBuffer target) throws IOException
From source file:net.ytbolg.mcxa.ForgeCheck.java
static String ReadFile(String path) throws FileNotFoundException, IOException { File file = new File(path); FileReader r = new FileReader(file); char c[] = new char[(int) file.length()]; r.read(c); r.close();/*from ww w . j a v a2 s.co m*/ return String.valueOf(c); }
From source file:com.alibaba.rocketmq.common.MixAll.java
public static final String file2String(final String fileName) { File file = new File(fileName); if (file.exists()) { char[] data = new char[(int) file.length()]; boolean result = false; FileReader fileReader = null; try {//from w ww .j a v a2s. co m fileReader = new FileReader(file); int len = fileReader.read(data); result = (len == data.length); } catch (IOException e) { // e.printStackTrace(); } finally { if (fileReader != null) { try { fileReader.close(); } catch (IOException e) { e.printStackTrace(); } } } if (result) { String value = new String(data); return value; } } return null; }
From source file:org.openqa.selenium.server.browserlaunchers.LauncherUtils.java
public static boolean isScriptFile(File aFile) { final char firstTwoChars[] = new char[2]; final FileReader reader; int charsRead; try {/* w w w . ja va2 s . com*/ reader = new FileReader(aFile); charsRead = reader.read(firstTwoChars); if (2 != charsRead) { return false; } return (firstTwoChars[0] == '#' && firstTwoChars[1] == '!'); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.apache.flex.forks.velocity.util.StringUtils.java
/** * Read the contents of a file and place them in * a string object.//from w ww. ja va2s . c o m * * @param String path to file. * @return String contents of the file. */ public static String fileContentsToString(String file) { String contents = ""; File f = new File(file); if (f.exists()) { try { FileReader fr = new FileReader(f); char[] template = new char[(int) f.length()]; fr.read(template); contents = new String(template); } catch (Exception e) { System.out.println(e); e.printStackTrace(); } } return contents; }
From source file:org.eclipse.orion.internal.server.core.metastore.SimpleMetaStoreUtil.java
/** * Get the JSON from the MetaFile in the provided parent folder. * @param parent The parent folder./*from w w w. j a v a 2 s. c o m*/ * @param name The name of the MetaFile * @return The JSON containing the data in the MetaFile. */ public static JSONObject readMetaFile(File parent, String name) { JSONObject jsonObject; try { if (!isMetaFile(parent, name)) { return null; } File savedFile = retrieveMetaFile(parent, name); FileReader fileReader = new FileReader(savedFile); char[] chars = new char[(int) savedFile.length()]; fileReader.read(chars); fileReader.close(); jsonObject = new JSONObject(new String(chars)); } catch (FileNotFoundException e) { throw new RuntimeException("Meta File Error, file not found", e); } catch (IOException e) { throw new RuntimeException("Meta File Error, file IO error", e); } catch (JSONException e) { throw new RuntimeException("Meta File Error, could not build JSON", e); } return jsonObject; }
From source file:org.dbflute.task.bs.DfAbstractTexenTask.java
protected static String fileContentsToString(String filePath) { String contents = ""; final File file = new File(filePath); if (file.exists()) { FileReader fr = null; try {// www . jav a2s . c o m fr = new FileReader(file); final char template[] = new char[(int) file.length()]; fr.read(template); contents = new String(template); } catch (Exception e) { throw new IllegalStateException("Failed to read the file: " + filePath, e); } finally { if (fr != null) { try { fr.close(); } catch (IOException ignored) { } } } } return contents; }
From source file:org.seasar.dbflute.task.bs.DfAbstractTexenTask.java
private static String fileContentsToString(String file) { String contents = ""; File f = new File(file); if (f.exists()) { FileReader fr = null; try {//from w ww . jav a 2 s .c o m fr = new FileReader(f); char template[] = new char[(int) f.length()]; fr.read(template); contents = new String(template); } catch (Exception e) { e.printStackTrace(); } finally { if (fr != null) { try { fr.close(); } catch (IOException ignored) { } } } } return contents; }
From source file:org.sharegov.cirm.utils.GenUtils.java
public static String readTextFile(File f) { try {/*from w w w. jav a 2s . c o m*/ FileReader reader = new FileReader(f); StringBuilder sb = new StringBuilder(); try { char[] buf = new char[4096]; for (int cnt = reader.read(buf); cnt > -1; cnt = reader.read(buf)) sb.append(buf, 0, cnt); } finally { reader.close(); } return sb.toString(); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:org.apache.axis2.corba.receivers.CorbaUtil.java
public static org.omg.CORBA.Object resolveObject(AxisService service, org.omg.CORBA_2_3.ORB orb) throws CorbaInvocationException { org.omg.CORBA.Object obj;/*from www . j ava2s . c o m*/ try { Parameter namingServiceUrl = service.getParameter(NAMING_SERVICE_URL); Parameter objectName = service.getParameter(OBJECT_NAME); Parameter iorFilePath = service.getParameter(IOR_FILE_PATH); Parameter iorString = service.getParameter(IOR_STRING); if (namingServiceUrl != null && objectName != null) { obj = orb.string_to_object(((String) namingServiceUrl.getValue()).trim()); NamingContextExt nc = NamingContextExtHelper.narrow(obj); obj = nc.resolve(nc.to_name(((String) objectName.getValue()).trim())); } else if (iorFilePath != null) { FileReader fileReader = new FileReader(((String) iorFilePath.getValue()).trim()); char[] buf = new char[1000]; fileReader.read(buf); obj = orb.string_to_object((new String(buf)).trim()); fileReader.close(); } else if (iorString != null) { obj = orb.string_to_object(((String) iorString.getValue()).trim()); } else { throw new CorbaInvocationException("cannot resolve object"); } } catch (NotFound notFound) { throw new CorbaInvocationException("cannot resolve object", notFound); } catch (CannotProceed cannotProceed) { throw new CorbaInvocationException("cannot resolve object", cannotProceed); } catch (InvalidName invalidName) { throw new CorbaInvocationException("cannot resolve object", invalidName); } catch (IOException e) { throw new CorbaInvocationException("cannot resolve object", e); } return obj; }
From source file:com.googlecode.t7mp.CommonsSetupUtilTest.java
private void checkResultFile() throws IOException { FileReader reader = new FileReader(target); char[] buffer = new char[10]; reader.read(buffer); reader.close();//w ww.j a v a 2s. c om String result = new String(buffer); Assert.assertEquals(MESSAGE, result.trim()); }