首页  >  文章  >  软件教程  >  Java如何将文档内容读取并显示在Label标签中

Java如何将文档内容读取并显示在Label标签中

WBOY
WBOY转载
2024-01-25 12:06:061216浏览

Java如何将文档内容读取并显示在Label标签中

Java如何将文档内容读取并显示在Label标签中

我以前学过软件开发,但已经有一段时间没有写代码了。如果你要我给你写代码并且出现问题,那我可能无法解决。每种软件开发语言都有自己的写法,所以我从Java换到C,再从C换到iOS也没有带来太大的意义,因为我对它们都不熟悉。

所以给你思路:

1: 找到R6

2: 从R6往后读取,一边读一边存起来 比如你写个数组 , 没读一行就往数组里面写一行(java里面是按行读取的我记得好像是.....)

3,:每读完一样判断每行的末尾字符是不是等于号,如果不是就继续,如果是就结束读取(这里写一个循环,读到等于号就跳出循环)

4:最后把数组里面的东西拿出来输出就好

每一种语言写这个东西 语法会变但是思路不会 至于具体代码 去翻翻书就全找到了

祝你学好JAVA

java实现:如何读取一个文本通过里面的文件路径读取文件内容

public class Test {

public static void main(String[] args) {

readFileByChars("d://test.txt");

}

public static void readFileByChars(String fileName) {

File file = new File(fileName);

Reader reader = null;

try {

if (file!=null) {

// 一次读多个字符

char[] tempchars = new char[30];

int charread = 0;

reader = new InputStreamReader(new FileInputStream(fileName));

// 读入多个字符到字符数组中,charread为一次读取字符数

while ((charread = reader.read(tempchars)) != -1) {

// 同样屏蔽掉r不显示

if ((charread == tempchars.length)

& (tempchars[tempchars.length - 1] != 'r')) {

System.out.print(tempchars);

} else {

for (int i = 0; i

if (tempchars[i] == 'r') {

continue;

} else {

System.out.print(tempchars[i]);

}

}

}

}

}

} catch (Exception e1) {

e1.printStackTrace();

} finally {

if (reader != null) {

try {

reader.close();

} catch (IOException e1) {

System.out.println("文件不存在");

}

}

}

}

}

以上是Java如何将文档内容读取并显示在Label标签中的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:docexcel.net。如有侵权,请联系admin@php.cn删除