gpt4 book ai didi

java - 如何从最后一行到第一行读取文本文件

转载 作者:行者123 更新时间:2023-12-01 15:43:24 25 4
gpt4 key购买 nike

我需要它反向运行,以便各行以与此相反的顺序显示。有没有一种快速的方法来翻转 TextView 或类似的东西?感谢您的帮助。

try {
// Create a URL for the desired page
URL url = new URL("text.txt");

// Read all the text returned by the server
BufferedReader MyBr = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
line = MyBr.readLine();
TextView textview1 = (TextView) findViewById(R.id.textView1);

StringBuilder total = new StringBuilder();

while ((line = MyBr.readLine()) != null) {
total.append(line + "\r\n");}

textview1.setText(total);
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/wonderfull.ttf");
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setTypeface(tf);
MyBr.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}

最佳答案

由于您要更改代码中的 UI,因此必须在 UI 线程上运行。当然,您知道在 UI 线程上执行这样的 I/O 是不允许的,并且很容易创建 ANR。所以我们假设这是伪代码。最好的选择是在阅读流时逆转事情。你可以insert at the front of the StringBuilder例如。

关于java - 如何从最后一行到第一行读取文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7617443/

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