gpt4 book ai didi

java - 字符串函数无法正常工作

转载 作者:行者123 更新时间:2023-11-29 05:45:50 24 4
gpt4 key购买 nike

这是我的程序。它不应该打印以单词“LTP”开头的句子或包含单词“TRAILING”的句子,但它不这样做。我不明白为什么。请帮我解决这个问题。

import java.io.*;

public class FileInputDemo {
public static void main(String args[]) {
// args.length is equivalent to argc in C
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream(
"C:\\Documents and Settings\\work\\Desktop\\New Folder\\New Folder\\02Apr2013log1.txt");
// Convert our input stream to a
// DataInputStream
DataInputStream in = new DataInputStream(fstream);
// Continue to read lines while
// there are still some left to read
while (in.available() != 0) {
String s=in.readLine();
// Print file line to screen
if(s.startsWith("LTP") || s.contains("TRAILING"))
{
continue;
}

System.out.println(in.readLine());
}

in.close();
} catch (Exception e) {
System.err.println("File input error");
}
}
}

这是输出

Long trade Managers in list (from Limit removal process) 2
LTP 9708.0 Current Stop 9723.0 for Order ID BAA0001 Mode:- TRAILING
9711.0 9716.0 9707.0 9707.0 9710.62
BullishFactor [openBullishFactor=NEUTRAL, closeBullishfactor=BEARISH, closeToOpenFactor=MODERATE_BEARISH]
BarSharing [sharingType=LLLH, bodySharing=0.44]
LTP 9707.0 Current Stop 9717.0 for Order ID BAA0001 Mode:- TRAILING

最佳答案

System.out.println 不应该打印字符串 吗?

 while (in.available() != 0) {
String s=in.readLine();

if(s.startsWith("LTP") || s.contains("TRAILING"))
{
continue;
}

System.out.println(s);
}

如果您要打印出 in.readLine(),则您刚刚阅读的那一行之后的行(存储在 s 中)可能包含“TRAILING”或以“LTP”。

关于java - 字符串函数无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15894181/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com