我想使用 JavaFX 显示 .txt 报告文件中的数据。在我的代码中,我尝试使用标签和 Vbox 在 GUI 中以多种格式显示信息到场景。但是,我将结果输出为 GUI 而不是控制台,结果很糟糕。我试图研究我的问题,但找不到解决问题所需的信息。
这是我需要使用 JavaFX 显示为 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) 我目前正在 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) 我有要在我的应用程序中读取的 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) 我有一个.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代码从中读取和写入。
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)”