嗨我需要從文件中刪除重複項並按相反順序打印該文件,例如「Ram is Ram is the Teacher」,則輸出應爲「Teacher the是Ram「。從文件中刪除重複文件,並用反向語句打印不使用java的文字
public class BufferedReaderExample {
public static void main(String[] args) {
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader("C:\\testing.txt"));
while ((sCurrentLine = br.readLine()) != null) {
System.out.println(sCurrentLine);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
你的代碼目前不做任何指望打印每一行。另外,輸出不清楚:如果重複,你想要什麼?保持第一個值?保持另一個? – Tunaki
是的我想第一次發生被刪除,最後一次發生打印例如「這是這個使用這個變量」它應該打印像變量這使用 我沒有做任何事情,除了閱讀,因爲我無法想象邏輯 – user4188607