标签: bufferedreader

如何使用 JavaFX GUI 应用程序显示 .txt 文件中的数据

我想使用 JavaFX 显示 .txt 报告文件中的数据。在我的代码中,我尝试使用标签和 Vbox 在 GUI 中以多种格式显示信息到场景。但是,我将结果输出为 GUI 而不是控制台,结果很糟糕。我试图研究我的问题,但找不到解决问题所需的信息。

这是我需要使用 JavaFX 显示为 GUI 应用程序的报告:

来自控制台的图像而不是来自 GUI

这是我的代码作为 GUI 显示的内容:

运行 GUI 时的图像

这是我的源代码:


package sample;

public class CustomerSale {

    // Details of reports
    private String zipCodeExtension;

    private int customerNumber;

    private String customerName;

    private int purchaseDate;

    private String make;

    private int purchasePrice;

    private int yearOfVehicle;

    private int satisfactionRating;


    // Create constructor argument

    public CustomerSale(String zipCodeExtension, int customerNumber, String customerName,
                        int purchaseDate, String make, int purchasePrice,
                        int yearOfVehicle, int satisfactionRating) {
        this.zipCodeExtension = zipCodeExtension;
        this.customerNumber …
Run Code Online (Sandbox Code Playgroud)

java javafx filereader bufferedreader

-1
推荐指数
1
解决办法
101
查看次数

与命令式解决方案相比,Java8 BufferedReader.lines() 流挂起程序

我目前正在 ServerSocket 中编写一个基本的网络服务器,我正在尝试使用 java 8 流来清理我的代码。这一直很顺利,但是当我尝试使用 BufferedReader 使用流读取请求时,我的程序挂起并且请求从未完全读入。我在下面列出了差异。

使用流:

InputStream stream = socket.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(stream));
System.out.println("----------REQUEST START---------");
List<String> rawRequest = in.lines()
    .peek(System.out::println)
    .map(line -> line.toString())
    .collect(Collectors.toList());
System.out.println("----------REQUEST END---------\n\n");
Run Code Online (Sandbox Code Playgroud)

没有流:

 InputStream stream = socket.getInputStream();
 BufferedReader in = new BufferedReader(new InputStreamReader(stream));
 List<String> rawRequest = new ArrayList<>();
    try {

      System.out.println("----------REQUEST START---------");
      // read only headers
      for (String line = in.readLine(); line != null && line.trim().length() > 0; line = in.readLine()) {
        System.out.println(line);
        rawRequest.add(line);
      }
      System.out.println("----------REQUEST END---------\n\n");
    } catch (IOException …
Run Code Online (Sandbox Code Playgroud)

java bufferedreader java-8

-2
推荐指数
1
解决办法
781
查看次数

BufferedReader 不读取整个文件并且不退出循环

我有要在我的应用程序中读取的 ini 文件,但问题是它没有读取整个文件,而是停留在 while 循环中。

我的代码:

FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);

String line = br.readLine();
Properties section = null;

while(line!=null){
     if(line.startsWith("[") && line.endsWith("]")){
         section = new Properties();
         this.config.put(line.substring(1, line.length() - 1), section);
     }else{
         String key = line.split("=")[0];
         String value = line.split("=")[1];
         section.setProperty(key, value);
     }

     line = br.readLine();
     System.out.println(line);

     // To continue reading newline. 
     //if i remove this, it will not continue reading the second header
     if(line.equals("")){ 
         line = br.readLine();
     }  
}

System.out.println("Done"); // Not printing …
Run Code Online (Sandbox Code Playgroud)

java bufferedreader java-8

-3
推荐指数
1
解决办法
91
查看次数

如何从文本文件中获取特定值

我有一个.txt文件:

80,90,100,110,120,130,140,150,160   
100,20,22,24,26,28,26,28,29,27   
110,30,32,34,36,37,39,37,39,40  
120,40,41,42,44,45,46,48,47,49
Run Code Online (Sandbox Code Playgroud)

表示百叶窗价格的表格,第一行是百叶窗的宽度,第一列没有80是高度.剩下的数字是价格.

我已经使用c#做了这个,但在java中我不知道该怎么做,在c#我的代码看起来像这样,一切都很好.有人能在java中向我展示同样的东西吗?theWidth和theHeight是我必须输入尺寸的文本字段.

                string[] lines = File.ReadAllLines(@"tabel.txt");
                string[] aux = lines[0].Split(',');
                for (int i = 0; i < aux.Length-1; i++)
                {
                    if (aux[i] == theWidth.ToString())
                    {
                        Console.WriteLine(aux[i]);
                        indiceLatime = i;
                    }
                }

                for (int i = 1; i < lines.Length; i++)
                {
                    aux = lines[i].Split(',');
                    if (aux[0] == theHeight.ToString())
                    {
                        showPrice.Text = aux[indiceLatime + 1];
                    }
                }
Run Code Online (Sandbox Code Playgroud)

在java中我尝试过这样的事情:

try {
        BufferedReader inputStream = new BufferedReader(new FileReader("tabel.txt"));
        int theWidth = 90;
        int theHeight = 100;
        int indiceLatime …
Run Code Online (Sandbox Code Playgroud)

java readline filereader bufferedreader readfile

-4
推荐指数
1
解决办法
6671
查看次数

什么是 getResourceAsStream() 仅用于重新输入输入,如何写入输出

所以基本上我有一个文件,java代码从中读取和写入。

BufferedReader 工作

BufferedReader bReader = new BufferedReader(
            new InputStreamReader(
                    getClass().getClassLoader().getResourceAsStream(fileName)
            )
);
Run Code Online (Sandbox Code Playgroud)

但是,BufferedWriter 不起作用:

BufferedWriter bWrite = new BufferedWriter(
                new OutputStreamWriter(
                    getClass().getClassLoader().getResourceAsStream(fileName)
                )
);
Run Code Online (Sandbox Code Playgroud)

“java.io.OutputStreamWriter”中的“OutputStreamWriter(java.io.OutputStream)”不能应用于“(java.io.InputStream)”

java bufferedwriter bufferedreader

-4
推荐指数
1
解决办法
57
查看次数