razão:
Como alguns tutoriais em vídeo são baixados on -line, alguns deles têm nomes muito longos e geralmente são promovidos por instituições ou sites, portanto, não é conveniente ver diretamente a introdução do vídeo, a primeira função a seguir foi feita.
Como o professor enviou muitas pastas no curso, foi muito problemático descobrir uma a uma, então a segunda função foi feita.
Acabei de aprender o conhecimento dos arquivos Java e do streaming recentemente, então por acaso praticar minhas habilidades. Este também é o meu primeiro programa exe, para que eu possa compartilhá -lo.
(Exportar o arquivo jar e usar a ferramenta exe4j para gerar o arquivo exe, esta parte é omitida)
Conhecimento usado:
Usa o conhecimento de arquivos, fluxos e conhecimento simples da GUI em Java.
Função:
Função 1: Remova certas palavras -chave no nome do arquivo e você também pode definir palavras substitutas.
Função 2: Extraia todos os arquivos de tipos específicos em um caminho e coloque -os em uma nova pasta. Se houver arquivos duplicados, eles serão classificados automaticamente e adicionam números para distingui -los.
Primeiro, olhe para a interface de inicialização e o arquivo exe gerado:
A primeira demonstração de recursos:
Nenhuma operação antes:
Após a operação: remova todas as mesmas palavras -chave na parte anterior
Há também uma função de retirada:
A segunda demonstração da função:
Antes da operação:
Após a operação:
Claro, há também uma função de retirada
Análise de código -fonte:
Aula de inicialização:
Pacote de pacote; public class Test {public static void main (string [] args) {// iniciar a GUI, ou seja, a interface do usuário new showgui ();}}Mostrar classe GUI:
pacote de pacote; importar java.awt.dimension; importar java.awt.flowlayout; importar java.awt.font; importar java.awt.image; importar java.awt.Toolkit; import.evEnMousee; java.awt.event.windowEvent; importar java.io.file; importar javax.swing.jbutton; importar javax.swing.jframe; importar javax.swing.jtextfield; classe pública Showgui {private jframe f; private jbutton button; private jbutton b2; private jbt {private jframe f; private jbutton button; private jbutton b2; private jbt {private jfame f; tf2; private jtextfield tf3; private jbutton b4; private jbutton b5; private jbutton b6; private jtextfield tf4; private jtextfield tf5; private jtextfield tf6; string estática privada; f.SetLayout (new FlowLayout ()); Image ICON = Toolkit.getDefaultToolkit (). GetImage ("Image/4.jpg"); // Defina o ícone do logotipo esquerdo superior F.SeticOnImage (Icon); // 6 Buttons B1 = novo JButton ("Start"); b2 = novo jbutton ("retrair"); b3 = novo jbutton ("exit"); b4 = new jbutton ("extração com um clique"); b5 = novo jbutton ("exit"); b6 = new jbutton ("exit"); // do tamanho de 6 botões b1.setPreferredReRe (nova dimensão (89, 39); 39)); B3.SetPreferredSize (nova dimensão (89, 39)); B4.SetPreferredSize (nova dimensão (89, 39)); B5.SetPreferredSize (New Dimension (89, 39)); B6. = novo JTextfield ("Insira Absolute_Path", 40); tf1.setFont (new Font ("Por favor, insira Absolute_Path", 40); Tf1.setFont (New Font ("Por favor, insira", Font.Plin, 25); 40); tf2.setFont (nova font ("Insira palavras -chave", font.plain, 25)); 126); tf4 = novo JTextfield ("Por favor, insira absoluta_path", 40); tf4.setFont (new Font ("Zongyi", font.plain, 25)); tf4.setBounds (200, 15, 550, 126); 40); tf5.setFont (new Font ("Por favor, insira", Font.Plain, 25)); 126); // Adicione o botão e a caixa de texto a F.Add (Tf1); F.Add (Tf2); F.Add (Tf3); F.Add (B1); F.Add (B2); F.Add (B3); F.Add (Tf4); F.Add (Tf5); F.Add (Tf6); F.Dd (B4); função de escuta de eventos myevent (); f.setVisible (true);} private void myEvent () {// Clique no canto superior direito × para sair f.addwindowlistener (new windowAdapter () {public void Windowclosing (WindowEvent e) {System.Exit (0);}}); {public void mouseclicked (mouseevent e) {s1 = tf1.getText (); // faz julgamentos sobre o valor na caixa de texto. Se nada estiver escrito, é tratado como vazio. O seguinte é semelhante ao if (s1.equals ("por favor, insira o caminho")) {s1 = "";} arquivo de arquivo = novo arquivo (s1); string test []; test = file.list (); renamefunction.test1 = tests; string s2 = tf2.getText); se (s2.equals ("Pleol emput; tf3.getText (); if (s3.equals ("Insira a substituição do replicação")) {s3 = "";} tente {// inicie a função renomeado renomefunction.sure (s1, s2, s3);} catch (exceção e1) {}}}); // clique no evento de resposta b2.addmousMEList (}}}); mouseclicked (mouseevent e) {tente {tente {if (! s1.equals ("por favor, insira o caminho")) {// comece a reverterename.revoke (s1);}} (exceção e2) {}} catch (exceção e1) {}}}} (); // clique mouseclicked (mouseevent e) {System.exit (0); (s2.equals ("por favor, insira absoluta_path")) {s2 = "";} if (s3.equals ("por favor, insira o destino_path")) {s3 = "";} if (s4.equals ("por favor, insira o filetystyTy") {s4 = ";} // iniciar a função da função SearchFileFileFile.TyStt. Evento de resposta b5.addmouselistener (new mouseAdApter () {public void mouseclicked (mouseevent e) {string s2 = tf5.getText (); // inicia a função de retirada removeTargetFile.StartDelete (s2);}}); // clique no resposta B6.D.D.D.DMOURTMOURTMOUR (S2);}}; mouseclicked (mouseevent e) {System.exit (0); // Saída}});}} Classe de configurações de imagem de fundo da GUI:
pacote guuze; importar javax.swing.Imageicon; importar javax.swing.jframe; importar javax.swing.jlabel; importar javax.swing.jpanel; public classe bgset estende JFRame, {private static final serialversionUid = 1l; 600); // caminho para a imagem de fundo. String path = "image/3.jpg"; imageicon background = new imageicon (caminho); Jlabel Label = new Jlabel (Background); Label.setBounds (0, 0, this.getwidth (), this.getHeight ()); jpanel imagePanel = (jpaNel) this.getContentPane (); imagePanel.setOpaque (false); this.getLayeredPane (). Add (etiqueta, novo número inteiro (Integer.min_value));}} Classe de renomeação de arquivos:
embalagem guuze; importar java.io.file; importar java.util.scanner; public class RenameFunction {scanner estático input = new scanner (system.in); public static string test1 []; public static void stere (string s1, string s2, string s3) throws Exception {file = file = novo (arquivo s3); nome para (int i = 0; i <test.length; i ++) {// determine se existe uma palavra -chave que você deseja remover se (teste [i] .IndexOf (s2)! = -1) {// salvar o nome renomeado de nomes de iSt [i] = teste [i] .replace (s2, s3); {for (Arquivo f: arquivos) {if (f.isfile ()) {// looping o nome da renomeação f.renameto (novo arquivo (s1 + "/" + teste [i ++]);}}}}}}} Renomear arquivos e retirar a classe de função:
pacote guuze; importar java.io.file; public class Revokerename {public static void revoke (string s1) lança exceção {// re-ative o arquivo de nomes original = novo arquivo (s1); files [] files = file.listfiles (); para (int i = 0; i <renameFunction.Test1.lng.Lucn; Observe que test1f.renameto (novo arquivo (s1 + "/" + renamefunction.test1 [i ++]));}}}}}} Classe de cópia de arquivo:
pacote guuze; importar java.io.bufferEnputStream; importar java.io.bufferoudOutputStream; importar java.io.file; importar java.io.fileInputStream; importar java.io.fileOutstream; importar java.io.ioxception; classe pública; Target_Path, String file_type) {// Inicie a função Loop Xunhuan (fonte_Path, Target_Path, file_type);} public static void xunhuan (string fonte_path, string string_path, string file_type) {file = file = fontes (origem); string e string e string, file (); (file.isfile () && file.getabsolutepath (). endswith (file_type)) {string new_path = target_path + "/" + file.getName (); file1 = new File (newpath); if (! file1.exists () {Try {file1.creatNewcept); O nome do arquivo é o mesmo, adicione um número antes do ponto para distinguir // Use //. para separá -lo em vez de.string [] arr = new_path.split ("//."); string new_path1 = arr [0] + count + "." + arr [1]; file1.renameto (novo arquivo (new_path1));} // é um arquivo, então comece a copiar o arquivo FileCopyByBufferStreamArray (file.getabsolutepath (), new_path);} else if (file.isf () &&! corpo, apenas não faça processamento} else {for (int i = 0; i <names.length; i ++) {// não é um arquivo, itera xunhuan (file.getabsolutepath () + "/" + names [i], target_path, file_type);}}}}}} stileiltbybers, filecutsburs (FILEANDER); Arquivos com conhecimento do arquivo de fluxos Arquivo = novo arquivo (srcfile); arquivo file1 = new File (TargetFile); FileInputStream fis = null; FileOutputStream fos = null; bufferInputStream bis = NULL; BufferoudOutStream Bos = null; Try {fis = new FileIngin (File); BufferInputStream (fis); bos = new bufferoudOutputStream (fos); int len = 0; byte [] b = novo byte [10]; while ((len = bis.read (b))! = -1) {bos.write (b, 0, len);} bos.lush (); {fis.close (); fos.close (); bis.close (); bos.close ();} catch (ioexception e) {}}}} Classe de retração de cópia de arquivo:
pacote guuze; importar java.io.file; public class RemoveTargetFile {public static void startDelete (string path) {file file = new File (path); deletefile (arquivo);} private static void deLeteFile (arquivo file) {// lembre exclua file.delete ();} else if (file.isdirectory ()) {file [] files = file.listfiles (); for (int i = 0; i <files.length; i ++) {// se não for um arquivo, itera deletefile (arquivos [i]);}}}}}O acima exposto é a renomeação do lote de arquivo java e a extração em lote de tipos específicos de arquivos introduzidos pelo editor. Espero que seja útil para todos. Se você tiver alguma dúvida, deixe -me uma mensagem e o editor responderá a todos a tempo. Muito obrigado pelo seu apoio ao site wulin.com!