Показать сообщение отдельно
Старый 17.05.2020, 10:15   #22 (permalink)
Завсегдатай
 
Регистрация: 24.01.2017
Сообщений: 521
Вы сказали Спасибо: 20
Поблагодарили 448 раз(а) в 165 сообщениях
Сказал(а) Фууу!: 1
Сказали Фууу! 0 раз(а) в 0 сообщениях
Откуда: Земля
По умолчанию

Xml пока не разделены, а продублированы.
Напишу прогу для разделения поблочно, когда надоест ручная работа.

список создаёт прога , сканируя вложенные папки:

Audi A7 2011

13

4G0907561 H21 4G0907561B 0053 000000000000000000F75AB9 4G8909863D 0036

----------



----------

package storage;

public class Runner {

public static void main(String[] args) {
UI ui = new UI();
ui.createAndShowGui(new ListCreator(), 200);
}
}

package storage;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class UI {
private JFrame frame = null;
private ListCreator listCreator;
private JButton butListOfUpdates = null;

public void createAndShowGui(ListCreator listCreator, int location) {
this.listCreator = listCreator;
frame = createFrame("ZDC List v2.0", location);
frame.setVisible(true);

}

private JFrame createFrame(String name, int location) {
frame = new JFrame(name);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setLocation(location, 200);
frame.setSize(600, 65);
frame.setContentPane(createPane());
return frame;
}

private JPanel createPane() {
JPanel TextsPanel = new JPanel(new FlowLayout());
JPanel buttonsPanel = new JPanel(new FlowLayout());
butListOfUpdates = buttonListOfUpdates();
buttonsPanel.add(butListOfUpdates);
buttonsPanel.add(onExit());
TextsPanel.add(buttonsPanel, BorderLayout.SOUTH);
return TextsPanel;
}

private JButton onExit() {
JButton sendMessage = new JButton("Выход");
sendMessage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
JButton sendMessage = (JButton) event.getSource();
onExit(sendMessage);
}
});
return sendMessage;
}

private void onExit(JButton sendMessage) {
System.exit(0);
}

private JButton buttonListOfUpdates() {
JButton sendMessage = new JButton("Обновить список");
sendMessage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
JButton sendMessage = (JButton) event.getSource();
listOfUpdates(sendMessage);
}
});
return sendMessage;
}

private void listOfUpdates(JButton sendMessage) {
try {
listCreator.run();
} catch (IOException e) {
butListOfUpdates.setText("ошибка файла");
butListOfUpdates.setEnabled(false);
e.printStackTrace();
}
}

}

package storage;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Queue;

public class ListCreator {
FileChannel fc;
ByteBuffer bf;

private void writeToFile(String message) throws IOException {
byte[] messageBytes = message.getBytes(Charset.forName("UTF-16"));
bf.put(messageBytes);
bf.flip();
fc.write(bf);
bf.clear();
}

public void run() throws IOException {
FileOutputStream fOut;
bf = ByteBuffer.allocateDirect(64 * 1024);
String root = ".\\";
File rootDir = new File(root);
File resultFile = new File(root + "\\list.txt");
fOut = new FileOutputStream(resultFile);
fc = fOut.getChannel();
Queue<File> model = new PriorityQueue<>();
Collections.addAll(model, rootDir.listFiles());
while (!model.isEmpty()) {
File modelFile = model.remove();
if (modelFile.isDirectory()) {
Queue<File> ecu = new PriorityQueue<>();
Collections.addAll(ecu, modelFile.listFiles());
String modelName = "-------" + modelFile.getName() + "-------\n";
writeToFile(modelName);
while (!ecu.isEmpty()) {
File ecuFile = ecu.remove();
if (ecuFile.isDirectory()) {
Queue<File> parameters = new PriorityQueue<>();
Collections.addAll(parameters, ecuFile.listFiles());
while (!parameters.isEmpty()) {
File parametersFile = parameters.remove();
if (parametersFile.isDirectory()) {
String ecuAndParams = ecuFile.getName() + " " + parametersFile.getName() + "\n";
writeToFile(ecuAndParams);
}
}
}
}
}
}
fOut.close();
}
}

Последний раз редактировалось Neo_; 17.05.2020 в 10:13..
Neo_ вне форума   Ответить с цитированием
Эти 2 пользователя(ей) сказали Спасибо Neo_ за сообщение:
BuHT (17.05.2020), Tadk (28.05.2020)