本文整理匯總了Java中java.io.InputStreamReader.ready方法的典型用法代碼示例。如果您正苦於以下問題:Java InputStreamReader.ready方法的具體用法?Java InputStreamReader.ready怎麽用?Java InputStreamReader.ready使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.InputStreamReader
的用法示例。
在下文中一共展示了InputStreamReader.ready方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import java.io.InputStreamReader; //導入方法依賴的package包/類
public static void main(String[] args) {
try {
/*
* trying to automatically configure include path by running cpp -v
*/
Process p = Runtime.getRuntime().exec("cpp -v");
InputStreamReader stdInput = new //BufferedReader(new
InputStreamReader(p.getInputStream()) ; //);
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while (stdInput.ready() ) {
System.out.print(stdInput.read());
}
}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}
}
示例2: promptLine
import java.io.InputStreamReader; //導入方法依賴的package包/類
protected String promptLine() throws IOException
{
if (startLine != null)
{
String line = startLine.trim();
println("> " + startLine);
startLine = null;
return line;
}
StringBuilder lineTyped = new StringBuilder();
InputStreamReader console = new InputStreamReader(System.in);
boolean prompted = false;
if (messages.isEmpty())
{
print(getPrompt()); // Otherwise nothing appears when quiet!
prompted = true;
}
while (true)
{
if (!messages.isEmpty())
{
if (prompted)
{
print("\n");
}
while (!messages.isEmpty())
{
String msg = messages.poll();
if (msg.length() > 0)
{
println(msg.toString());
}
}
print(getPrompt());
print(lineTyped.toString());
prompted = true;
}
while (console.ready())
{
int c = console.read();
if (c == '\r')
{
continue;
}
else if (c == '\n' || c == -1)
{
return lineTyped.toString().trim();
}
else
{
lineTyped.append((char)c);
}
}
Utils.milliPause(10);
}
}
示例3: fileStream
import java.io.InputStreamReader; //導入方法依賴的package包/類
public static void fileStream() {
try {
File f = new File("mkdirs/test/filetest.txt");
FileOutputStream fop = new FileOutputStream(f);
// 構建FileOutputStream對象,文件不存在會自動新建
OutputStreamWriter writer = new OutputStreamWriter(fop, "gbk");
// 構建OutputStreamWriter對象,參數可以指定編碼,默認為操作係統默認編碼,windows上是gbk
writer.append("中文輸入");
// 寫入到緩衝區
writer.append("\r\n");
// 換行
writer.append("English");
// 刷新緩存衝,寫入到文件,如果下麵已經沒有寫入的內容了,直接close也會寫入
writer.close();
// 關閉寫入流,同時會把緩衝區內容寫入文件,所以上麵的注釋掉
fop.close();
// 關閉輸出流,釋放係統資源
FileInputStream fip = new FileInputStream(f);
// 構建FileInputStream對象
InputStreamReader reader = new InputStreamReader(fip, "UTF-8");
// 構建InputStreamReader對象,編碼與寫入相同
StringBuffer sb = new StringBuffer();
while (reader.ready()) {
sb.append((char) reader.read());
// 轉成char加到StringBuffer對象中
}
System.out.println(sb.toString());
reader.close();
// 關閉讀取流
fip.close();
// 關閉輸入流,釋放係統資源
} catch (Exception e) {
}
}