本文整理了Java中java.io.InputStreamReader.close()
方法的一些代码示例,展示了InputStreamReader.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。InputStreamReader.close()
方法的具体详情如下:
包路径:java.io.InputStreamReader
类名称:InputStreamReader
方法名:close
[英]Closes this reader. This implementation closes the source InputStream and releases all local storage.
[中]关闭此读卡器。此实现关闭源InputStream并释放所有本地存储。
代码示例来源:origin: alibaba/jstorm
static Map loadYamlConf(String f) throws IOException {
InputStreamReader reader = null;
try {
FileInputStream fis = new FileInputStream(f);
reader = new InputStreamReader(fis, UTF8);
return (Map) yaml.load(reader);
} finally {
if (reader != null)
reader.close();
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
public void run() {
try {
InputStreamReader isr = new InputStreamReader (is);
BufferedReader br = new BufferedReader (isr);
String s = null;
//noinspection ConstantConditions
while (s == null && shouldRun) {
while ( (s = br.readLine()) != null ) {
outputFileHandle.write(s);
outputFileHandle.write("\n");
}
Thread.sleep(1000);
}
isr.close();
br.close();
outputFileHandle.flush();
} catch (Exception ex) {
System.out.println ("Problem reading stream :"+is.getClass().getCanonicalName()+ " "+ ex);
ex.printStackTrace ();
}
}
代码示例来源:origin: stackoverflow.com
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public String readFile(String filename)
{
String content = null;
File file = new File(filename); //for ex foo.txt
FileReader reader = null;
try {
reader = new FileReader(file);
char[] chars = new char[(int) file.length()];
reader.read(chars);
content = new String(chars);
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(reader !=null){reader.close();}
}
return content;
}
代码示例来源:origin: alipay/sofa-rpc
/**
* 读取类相对路径内容
*
* @param file 文件
* @return 文件内容(按行)
* @throws IOException 发送IO异常
*/
public static List<String> readLines(File file) throws IOException {
List<String> lines = new ArrayList<String>();
InputStreamReader reader = null;
BufferedReader bufferedReader = null;
try {
reader = new FileReader(file);
bufferedReader = new BufferedReader(reader);
String lineText = null;
while ((lineText = bufferedReader.readLine()) != null) {
lines.add(lineText);
}
return lines;
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
if (reader != null) {
reader.close();
}
}
}
代码示例来源:origin: stackoverflow.com
FileReader fr = null;
try {
fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String line = null;
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (fr != null) {
try {
fr.close();
} catch (IOException e) {
// This is unrecoverable. Just report it and move on
e.printStackTrace();
}
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
public TraditionalSimplifiedCharacterMap(String path) {
// TODO: gzipped maps might be faster
try {
FileInputStream fis = new FileInputStream(path);
InputStreamReader isr = new InputStreamReader(fis, "utf-8");
BufferedReader br = new BufferedReader(isr);
init(br);
br.close();
isr.close();
fis.close();
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
代码示例来源:origin: alipay/sofa-rpc
/**
* 读取类相对路径内容
*
* @param file 文件
* @return 文件内容(按行)
* @throws IOException 发送IO异常
*/
public static List<String> readLines(File file) throws IOException {
List<String> lines = new ArrayList<String>();
InputStreamReader reader = null;
BufferedReader bufferedReader = null;
try {
reader = new FileReader(file);
bufferedReader = new BufferedReader(reader);
String lineText = null;
while ((lineText = bufferedReader.readLine()) != null) {
lines.add(lineText);
}
return lines;
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
if (reader != null) {
reader.close();
}
}
}
代码示例来源:origin: apache/nifi
public void process(InputStream in) throws IOException {
InputStreamReader r = new InputStreamReader(in, charset);
c.call(r);
r.close();
}
});
代码示例来源:origin: stackoverflow.com
FileReader r = new FileReader(path);
try {
Scanner s = new Scanner(new BufferedReader(r));
...
} finally {
r.close();
}
代码示例来源:origin: stackoverflow.com
FileReader fileReader = new FileReader(privateKey);
PEMReader r = new PEMReader(fileReader, new DefaultPasswordFinder(keyPassword));
try {
} finally {
r.close();
fileReader.close();
代码示例来源:origin: cmusphinx/sphinx4
protected void loadMapping(InputStream inputStream) throws IOException {
InputStreamReader isr = new InputStreamReader(inputStream);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line);
if (st.countTokens() != 2) {
throw new IOException("Wrong file format");
}
mapping.put(st.nextToken(), st.nextToken());
}
br.close();
isr.close();
inputStream.close();
}
}
代码示例来源:origin: stackoverflow.com
public static void main(String... s) throws Exception {
FileReader fr = new FileReader("read.txt");
BufferedReader br = new BufferedReader(fr);
String line = "";
List<String> list = new ArrayList<String>(0);
while ((line = br.readLine()) != null) {
// process the line.
list.add(line);
}
br.close();
fr.close();
}
代码示例来源:origin: apache/storm
public static Map<String, Object> fromCompressedJsonConf(byte[] serialized) {
try {
ByteArrayInputStream bis = new ByteArrayInputStream(serialized);
InputStreamReader in = new InputStreamReader(new GZIPInputStream(bis));
Object ret = JSONValue.parseWithException(in);
in.close();
return (Map<String, Object>) ret;
} catch (IOException | ParseException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: stackoverflow.com
FileReader fr = null;
try {
fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String line = null;
} catch (FileNotFoundException fnf) {
fnf.printStackTrace();
} finally {
if( fr != null)
fr.close();
}
代码示例来源:origin: stackoverflow.com
try {
FileReader in = new FileReader("java-new.html");
Html2Text parser = new Html2Text();
parser.parse(in);
in.close();
System.out.println(parser.getText());
} catch (Exception e) {
代码示例来源:origin: stanfordnlp/CoreNLP
public void translateFile(String input, String output) {
try {
FileInputStream fis = new FileInputStream(input);
InputStreamReader isr = new InputStreamReader(fis, "utf-8");
BufferedReader br = new BufferedReader(isr);
FileOutputStream fos = new FileOutputStream(output);
OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
BufferedWriter bw = new BufferedWriter(osw);
translateLines(br, bw);
bw.close();
osw.close();
fos.close();
br.close();
isr.close();
fis.close();
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
代码示例来源:origin: stackoverflow.com
public boolean checkInput(String input)
{
FileReader in = new FileReader("C:/test.txt");
BufferedReader br = new BufferedReader(in);
String line;
while ((line = br.readLine()) != null) {
if(line.contains(input))
return true;
}
in.close();
return false;
}
代码示例来源:origin: ctripcorp/apollo
InputStreamReader esr = null;
try {
isr = new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8);
CharStreams.toString(isr);
} catch (IOException e) {
esr = new InputStreamReader(errorStream, StandardCharsets.UTF_8);
try {
CharStreams.toString(esr);
if (isr != null) {
try {
isr.close();
} catch (IOException ex) {
esr.close();
} catch (IOException ex) {
代码示例来源:origin: stackoverflow.com
throw new IllegalArgumentException("Resource can not be found: " + filePath);
reader = new FileReader(filePath);
reader.close();
代码示例来源:origin: stackoverflow.com
InputStreamReader isr = new InputStreamReader(ubis);
BufferedReader br = new BufferedReader(isr);
System.out.println(br.readLine());
br.close();
isr.close();
ubis.close();
fis.close();
isr = new InputStreamReader(ubis);
br = new BufferedReader(isr);
System.out.println(br.readLine());
br.close();
isr.close();
ubis.close();
fis.close();
内容来源于网络,如有侵权,请联系作者删除!