本文整理汇总了Java中java.util.Scanner.hasNextLine方法的典型用法代码示例。如果您正苦于以下问题:Java Scanner.hasNextLine方法的具体用法?Java Scanner.hasNextLine怎么用?Java Scanner.hasNextLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Scanner
的用法示例。
在下文中一共展示了Scanner.hasNextLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import java.util.Scanner; //导入方法依赖的package包/类
private static void load(Language language, String string) throws Exception {
Scanner scanner = new Scanner(string);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.startsWith("#")) continue;
int index = line.indexOf("=");
if (index == -1) continue;
String str = line.substring(0, index).toLowerCase();
String localization = line.substring(index + 1);
language.add(str, localization);
}
scanner.close();
}
示例2: registerAllIPCams
import java.util.Scanner; //导入方法依赖的package包/类
public static void registerAllIPCams(String fname)
{
File f = new File(fname);
if(f.exists()&&f.isFile())
{
try {
Scanner scan = new Scanner(f);
while(scan.hasNextLine())
{
registerIPCam(scan.nextLine());
}
scan.close();
} catch (FileNotFoundException e) {
}
}
}
示例3: init
import java.util.Scanner; //导入方法依赖的package包/类
public static void init() throws FileNotFoundException, IOException {
Scanner scanner = new Scanner(file);
scanner.nextLine(); //Skip the first (Title) line
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.equals("*") || line.split(",").length < 3) { //To prevent reading the same line twice AND prevent reading a corrupted line
break;
}
scores.put(Integer.parseInt(line.split(",")[1]), line.split(",")[0]); //Only looks at the first two columns (name and highscore)
}
sortScores();
//printScores();
}
示例4: processFile
import java.util.Scanner; //导入方法依赖的package包/类
/** */
public Map processFile() throws FileNotFoundException {
//FileReader is used, not File, since File is not Closeable
scanner = new Scanner(new FileReader(file));
try {
//Scanner to get each line
while (scanner.hasNextLine()) {
processLine(scanner.nextLine());
}
} finally {
//Close the underlying stream
scanner.close();
}
return map;
}
示例5: isVnrMapped
import java.util.Scanner; //导入方法依赖的package包/类
/**
* Function that indicates if the virtual link mapping could be performed
*
* @return boolean value indicating if the virtual link mapping could be
* performed
* @throws FileNotFoundException
*/
@SuppressWarnings("static-access")
public boolean isVnrMapped() throws FileNotFoundException {
try{
Thread.currentThread().sleep(500);
}catch(InterruptedException ie){
//If this thread was interrupted by another thread
}
String filePath = MATLAB_PATH + MAPPING_PERFORMED + virtualNetReqNumber;
fFile = new File(filePath);
Scanner scanner = new Scanner(fFile);
String[] decision;
while (scanner.hasNextLine()) {
decision = scanner.nextLine().split(" ");
if (((int) (Double.parseDouble(decision[1]))) == 1) {
return true;
} else {
return false;
}
}
scanner.close();
return false;
}
示例6: getTemplateFileContent
import java.util.Scanner; //导入方法依赖的package包/类
/**
* Read template with given template name
*
* @param template
* @return template string
*/
private String getTemplateFileContent(String template) {
StringBuilder builder = new StringBuilder();
InputStream in = getClass().getResourceAsStream(template);
Scanner scanner = new Scanner(in);
while (scanner.hasNextLine()) {
builder.append(scanner.nextLine());
}
return builder.toString();
}
示例7: getPartitionsLinesByType
import java.util.Scanner; //导入方法依赖的package包/类
public static HashMap<String, Integer> getPartitionsLinesByType(IDocument document,
String partitionType) {
HashMap<String, Integer> lines = new HashMap<String, Integer>();
final Scanner scanner = new Scanner(document.get());
int lineNumber = 0;
try {
while (scanner.hasNextLine()) {
final String line = scanner.nextLine();
final int offset = document.getLineOffset(lineNumber);
if (document.getPartition(offset).getType().equals(partitionType)) {
lines.put(line, lineNumber);
}
lineNumber++;
}
} catch (BadLocationException e) {
e.printStackTrace();
} finally {
if (scanner != null)
scanner.close();
}
return lines;
}
示例8: loadObstaclesFromPoses
import java.util.Scanner; //导入方法依赖的package包/类
public void loadObstaclesFromPoses() {
try {
Scanner in = new Scanner(new FileReader(posesFileName));
while (in.hasNextLine()) {
String line = in.nextLine().trim();
if (line.length() != 0 && !line.startsWith("#")) {
String[] oneline = line.split(" |\t");
if (oneline.length == 4) {
Pose ps = null;
String obsName = oneline[0];
obstacleNames.add(obsName);
ps = new Pose(
new Double(oneline[1]).doubleValue(),
new Double(oneline[2]).doubleValue(),
new Double(oneline[3]).doubleValue());
Geometry obs = makeObstacle(ps);
int id = obstacles.size()-1;
panel.addGeometry("obs_"+id, obs, false, false, true, "#cc3300");
selectedObsInt.add(id);
}
}
}
in.close();
clearPathPointSelection();
highlightObstacles();
}
catch (FileNotFoundException e) { e.printStackTrace(); }
}
示例9: parseSubTreeByLines
import java.util.Scanner; //导入方法依赖的package包/类
public static NbMenuItem parseSubTreeByLines(String filename) {
Hashtable<Integer, NbMenuItem> levelRoots = new Hashtable<Integer, NbMenuItem>();
NbMenuItem mainNode = new NbMenuItem();
int actLevel = -1;
levelRoots.put(new Integer(actLevel), mainNode);
try {
Scanner scanner = new Scanner(new File(filename));
while (scanner.hasNextLine()) {
String nextLine = scanner.nextLine();
int spaces = 0;
while (nextLine.charAt(spaces) == ' ') {
spaces++;
}
nextLine = nextLine.substring(spaces).trim();
NbMenuItem newNode = new NbMenuItem();
newNode.setName(nextLine);
actLevel = spaces / 4;//every level is intended
//NbMenuItem node =
ArrayList<NbMenuItem> submenu = levelRoots.get(actLevel - 1).getSubmenu();
if (submenu == null) {
submenu = new ArrayList<NbMenuItem>();
}
submenu.add(newNode);
levelRoots.get(actLevel - 1).setSubmenu(submenu);//set new submenu with the new node in it
levelRoots.put(actLevel, newNode);
}
} catch (FileNotFoundException ex) {
Logger.getLogger(Utilities.class.getName()).log(Level.SEVERE, null, ex);
}
return mainNode;
}
示例10: extractJSessionId
import java.util.Scanner; //导入方法依赖的package包/类
private String extractJSessionId(String response) {
Scanner scanner = new Scanner(response);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.startsWith("Set-Cookie")) {
return Arrays.asList(line.split(":")[1].split(";"))
.stream()
.filter(s -> s.contains("JSESSIONID"))
.findAny()
.get();
}
}
return null;
}
示例11: getInstance
import java.util.Scanner; //导入方法依赖的package包/类
public static Languages getInstance(final String languagesResourceName) {
// read languages list
final Set<String> ls = new HashSet<String>();
final InputStream langIS = Languages.class.getClassLoader().getResourceAsStream(languagesResourceName);
if (langIS == null) {
throw new IllegalArgumentException("Unable to resolve required resource: " + languagesResourceName);
}
final Scanner lsScanner = new Scanner(langIS, ResourceConstants.ENCODING);
try {
boolean inExtendedComment = false;
while (lsScanner.hasNextLine()) {
final String line = lsScanner.nextLine().trim();
if (inExtendedComment) {
if (line.endsWith(ResourceConstants.EXT_CMT_END)) {
inExtendedComment = false;
}
} else {
if (line.startsWith(ResourceConstants.EXT_CMT_START)) {
inExtendedComment = true;
} else if (line.length() > 0) {
ls.add(line);
}
}
}
} finally {
lsScanner.close();
}
return new Languages(Collections.unmodifiableSet(ls));
}
示例12: seekScannerToEnd
import java.util.Scanner; //导入方法依赖的package包/类
public static String seekScannerToEnd(Scanner scan) {
StringBuilder data = new StringBuilder();
while (scan.hasNextLine()) {
data.append(scan.nextLine());
data.append("\n");
}
return data.toString().trim();
}
示例13: readPath
import java.util.Scanner; //导入方法依赖的package包/类
private void readPath() {
ArrayList<PoseSteering> ret = new ArrayList<PoseSteering>();
try {
Scanner in = new Scanner(new FileReader(pathFileName));
while (in.hasNextLine()) {
String line = in.nextLine().trim();
if (line.length() != 0 && !line.trim().startsWith("#")) {
String[] oneline = line.split(" |\t");
PoseSteering ps = null;
if (oneline.length == 4) {
ps = new PoseSteering(
new Double(oneline[0]).doubleValue(),
new Double(oneline[1]).doubleValue(),
new Double(oneline[2]).doubleValue(),
new Double(oneline[3]).doubleValue());
}
else {
ps = new PoseSteering(
new Double(oneline[0]).doubleValue(),
new Double(oneline[1]).doubleValue(),
new Double(oneline[2]).doubleValue(),
0.0);
}
ret.add(ps);
}
}
in.close();
}
catch (FileNotFoundException e) { e.printStackTrace(); }
this.path = ret;
for (int i = 0; i < path.size(); i++) {
Pose pose = path.get(i).getPose();
panel.addArrow(""+i, pose, Color.gray);
}
panel.updatePanel();
}
示例14: modifyStartScript
import java.util.Scanner; //导入方法依赖的package包/类
@Override
protected String modifyStartScript(String content) throws RaspError {
int modifyConfigState = NOTFOUND;
StringBuilder sb = new StringBuilder();
Scanner scanner = new Scanner(content);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (FOUND == modifyConfigState) {
sb.append(OPENRASP_CONFIG);
modifyConfigState = DONE;
}
if (DONE == modifyConfigState) {
if (OPENRASP_REGEX.matcher(line).matches()) {
continue;
}
}
if (line.startsWith("JAVA_OPTS=") && NOTFOUND == modifyConfigState) {
modifyConfigState = FOUND;
}
sb.append(line).append(LINE_SEP);
}
if (NOTFOUND == modifyConfigState) {
throw new RaspError(E10001 + "\"JAVA_OPTS=\"");
}
return sb.toString();
}
示例15: loadLocationAndPathData
import java.util.Scanner; //导入方法依赖的package包/类
/**
* Load location and path data from a file
* @param fileName The file to load the data from
*/
public static void loadLocationAndPathData(String fileName) {
try {
Scanner in = new Scanner(new FileReader(fileName));
File f = new File(fileName);
pathPrefix = f.getAbsolutePath().substring(0,f.getAbsolutePath().lastIndexOf(File.separator))+File.separator;
while (in.hasNextLine()) {
String line = in.nextLine().trim();
if (line.length() != 0 && !line.startsWith("#")) {
String[] oneline = line.split(" |\t");
Pose ps = null;
if (line.contains("->")) {
paths.put(oneline[0]+oneline[1]+oneline[2], oneline[3]);
System.out.println("Added to paths: " + oneline[0]+oneline[1]+oneline[2] + " --> " + oneline[3]);
}
else {
String locationName = oneline[0];
ps = new Pose(
new Double(oneline[1]).doubleValue(),
new Double(oneline[2]).doubleValue(),
new Double(oneline[3]).doubleValue());
locations.put(locationName, ps);
}
}
}
in.close();
}
catch (FileNotFoundException e) { e.printStackTrace(); }
}