0
我有一條nmea消息。我想寫出一個只有$GPGSV
行的其他文件。這裏是我的代碼,它現在爲每行寫入布爾值(true,false)。我怎樣才能寫出行的值?將指定的行寫入新文件
public static void main(String[] args) throws IOException {
File inputFile = new File("proba.txt");
File tempFile = new File("kiir.txt");
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
String currentLine;
while((currentLine = reader.readLine()) != null) {
// trim newline when comparing with lineToRemove
String trimmedLine = currentLine.trim();
writer.write(currentLine.startsWith("$GPGSV") + System.getProperty("line.separator"));
}
writer.close();
reader.close();
在寫入時使用'if'(或者請求原作者爲您添加一個) – 2016-03-05 08:05:09
一些閱讀:https://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html – 2016-03-05 08:06:45
一些示例輸入和輸出行,以便每個人都可以瞭解你在代碼中缺少的內容? – Mahendra