本文整理匯總了Java中java.io.BufferedReader.readLine方法的典型用法代碼示例。如果您正苦於以下問題:Java BufferedReader.readLine方法的具體用法?Java BufferedReader.readLine怎麽用?Java BufferedReader.readLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.BufferedReader
的用法示例。
在下文中一共展示了BufferedReader.readLine方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: obterDadosBD
import java.io.BufferedReader; //導入方法依賴的package包/類
public static void obterDadosBD() throws IOException{
try {
FileReader conf = new FileReader("config.txt");
BufferedReader lerArq = new BufferedReader(conf);
ConnectionFactory.DRIVER = lerArq.readLine();
ConnectionFactory.URL = lerArq.readLine();
ConnectionFactory.USER = lerArq.readLine();
ConnectionFactory.PASS = lerArq.readLine();
conf.close();
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(null,"Erro ao abrir o arquivo config.txt");
}
}
示例2: read
import java.io.BufferedReader; //導入方法依賴的package包/類
/**
* Read invalid JSON format.
*/
protected void read(final ProtocolFactory protocols, final Local file) throws AccessDeniedException {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(file.getInputStream(), Charset.forName("UTF-8")));
try {
String l;
while((l = in.readLine()) != null) {
Matcher array = Pattern.compile("\\[(.*?)\\]").matcher(l);
while(array.find()) {
Matcher entries = Pattern.compile("\\{(.*?)\\}").matcher(array.group(1));
while(entries.find()) {
final String entry = entries.group(1);
this.read(protocols, entry);
}
}
}
}
finally {
IOUtils.closeQuietly(in);
}
}
catch(IOException e) {
throw new AccessDeniedException(e.getMessage(), e);
}
}
示例3: main
import java.io.BufferedReader; //導入方法依賴的package包/類
public static void main(String ... ags)throws Exception
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine());
for(int i=0;i<n;i++)
{
StringTokenizer tk = new StringTokenizer(in.readLine());
int a = Integer.parseInt(tk.nextToken());
int b = Integer.parseInt(tk.nextToken());
int c = Integer.parseInt(tk.nextToken());
int sum=a+b;
System.out.print(sum +" ");
for(int j=1;j<c;j++)
{
sum = sum+(power(j)*b);
System.out.print(sum + " ");
}
System.out.println();
}
}
示例4: loadDefinition
import java.io.BufferedReader; //導入方法依賴的package包/類
/**
* Load the definition file and parse each of the sections
*
* @param def The location of the definitions file
* @param trans The color to be treated as transparent
* @throws SlickException Indicates a failure to read or parse the definitions file
* or referenced image.
*/
private void loadDefinition(String def, Color trans) throws SlickException {
BufferedReader reader = new BufferedReader(new InputStreamReader(ResourceLoader.getResourceAsStream(def)));
try {
image = new Image(basePath+reader.readLine(), false, filter, trans);
while (reader.ready()) {
if (reader.readLine() == null) {
break;
}
Section sect = new Section(reader);
sections.put(sect.name, sect);
if (reader.readLine() == null) {
break;
}
}
} catch (Exception e) {
Log.error(e);
throw new SlickException("Failed to process definitions file - invalid format?", e);
}
}
示例5: makeMap
import java.io.BufferedReader; //導入方法依賴的package包/類
public static void makeMap() {
try {
InputStream is = EtFuturum.class.getResourceAsStream("/assets/OceanMonument.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String s;
while ((s = br.readLine()) != null) {
String[] data = s.split("-");
data[0] = data[0].trim();
data[0] = data[0].substring(1, data[0].length() - 1);
data[1] = data[1].trim();
String[] coords = data[0].split(",");
WorldCoord key = new WorldCoord(Integer.parseInt(coords[0].trim()), Integer.parseInt(coords[1].trim()), Integer.parseInt(coords[2].trim()));
int value = Integer.parseInt(data[1]);
map.put(key, value);
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例6: main
import java.io.BufferedReader; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String name = reader.readLine();
if (name.isEmpty()) break;
int age = Integer.parseInt(reader.readLine());
int weight = Integer.parseInt(reader.readLine());
int tailLength = Integer.parseInt(reader.readLine());
Cat cat = new Cat(name, age, weight, tailLength);
CATS.add(cat);
}
printList();
}
示例7: getReceive
import java.io.BufferedReader; //導入方法依賴的package包/類
/**
* 獲取回複消息
*
* @param con
* @return
* @throws IOException
*/
private static String getReceive(HttpURLConnection con) throws IOException {
InputStream is = null;
try {
is = con.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is,
defaulEncoding));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null)
sb.append(line);
return sb.toString();
} finally {
if (null != is)
is.close();
}
}
示例8: getParameter
import java.io.BufferedReader; //導入方法依賴的package包/類
public static <T> T getParameter(HttpServletRequest request, Class<T> cls) {
String str, wholeStr = "";
try {
BufferedReader br = request.getReader();
while ((str = br.readLine()) != null) {
wholeStr += str;
}
if (StringUtils.isNotBlank(wholeStr)) {
logger.info("request===>" + wholeStr);
request.setAttribute("iBase4J.Parameters", wholeStr);
return InstanceUtil.parse(wholeStr, cls);
}
} catch (Exception e) {
logger.error("", e);
}
logger.info("request===>" + JSON.toJSONString(request.getParameterMap()));
return Request2ModelUtil.covert(cls, request);
}
示例9: readProcessStreamImpl
import java.io.BufferedReader; //導入方法依賴的package包/類
private static void readProcessStreamImpl(final InputStream stream, boolean remoteStream, final LineProcessor lineProcessor) throws IOException {
if (stream == null) {
lineProcessor.reset();
lineProcessor.close();
} else {
lineProcessor.reset();
final BufferedReader br = getReader(stream, remoteStream);
try {
String line;
while ((line = br.readLine()) != null) {
lineProcessor.processLine(line);
}
} finally {
lineProcessor.close();
if (br != null) {
br.close();
}
}
}
}
示例10: read
import java.io.BufferedReader; //導入方法依賴的package包/類
/**
* Read the contents of the file indicated by fileName
*/
public static String read(InputStream is) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
while (br.ready()) {
String line = br.readLine();
sb.append("\n");
sb.append(line);
}
String data = sb.toString();
return data;
}
示例11: run
import java.io.BufferedReader; //導入方法依賴的package包/類
public void run() {
try {
System.out.println("Connected to " + s);
BufferedReader is = new BufferedReader(new InputStreamReader(s
.getInputStream()));
String result;
while ((result = is.readLine()) != null) {
String timePercentCount[] = result.split(" ");
if (timePercentCount.length != 5) {
System.err.println("Got " + result + " from " + s
+ " exitng.");
throw new IOException(result);
}
long time = Long.parseLong(timePercentCount[0]);
// int percent = Integer.parseInt(timePercentCount[1]);
int count = Integer.parseInt(timePercentCount[2]);
int errs = Integer.parseInt(timePercentCount[3]);
if (errs > 0) {
System.out.println(s + " Got an error! " + errs);
}
add(time, count, s);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
close();
}
}
示例12: launchWordCount
import java.io.BufferedReader; //導入方法依賴的package包/類
static String launchWordCount(URI fileSys, JobConf conf, String input,
int numMaps, int numReduces)
throws IOException {
final Path inDir = new Path("/testing/wc/input");
final Path outDir = new Path("/testing/wc/output");
FileSystem fs = FileSystem.get(fileSys, conf);
configureWordCount(fs, conf, input, numMaps, numReduces, inDir, outDir);
JobClient.runJob(conf);
StringBuffer result = new StringBuffer();
{
Path[] parents = FileUtil.stat2Paths(fs.listStatus(outDir.getParent()));
Path[] fileList = FileUtil.stat2Paths(fs.listStatus(outDir,
new Utils.OutputFileUtils.OutputFilesFilter()));
for(int i=0; i < fileList.length; ++i) {
BufferedReader file =
new BufferedReader(new InputStreamReader(fs.open(fileList[i])));
String line = file.readLine();
while (line != null) {
result.append(line);
result.append("\n");
line = file.readLine();
}
file.close();
}
}
return result.toString();
}
示例13: readTxt
import java.io.BufferedReader; //導入方法依賴的package包/類
@SuppressWarnings("resource")
public static void readTxt(String path2) throws Exception
{
Reader reader = new FileReader(path2);;
BufferedReader bufr = new BufferedReader(reader);
StringBuffer buf = new StringBuffer();
String line = null;
String s = null;
int k = 0;
while ((line = bufr.readLine()) != null)
{
if (line.contains("答案"))
{
arr1[k] = line;
line = "aaaaa";
k++;
}
buf.append(line + "\r\n");
}
s = buf.toString();
arr2 = s.split("aaaaa");
for (int j = 0; j < arr2.length; j++)
{
arr[j] = arr2[j];
}
bufr.close();
}
示例14: readFromFile
import java.io.BufferedReader; //導入方法依賴的package包/類
/**
* Ask a file for the username and password.
*/
private void readFromFile() {
try {
FileReader fr = new FileReader(this.credentials);
BufferedReader br = new BufferedReader(fr);
this.username = br.readLine();
this.password = br.readLine();
br.close();
fr.close();
}
catch (Exception e) {
this.username = "";
this.password = "";
}
}
示例15: getNextLine
import java.io.BufferedReader; //導入方法依賴的package包/類
private String getNextLine(BufferedReader br) {
try {
return br.readLine();
}
catch (Exception e) {
return null;
}
}