package com.chillax_li.main;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import com.chillax_li.util.ApkUtil;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileSystemView;
/**
*
* @author Administrator
*/
public class MainTest extends javax.swing.JFrame {
private File f = null;
private List<String> pathList = new ArrayList<String>();;
/**
* Creates new form NewJFrame
*/
public MainTest() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("选择文件位置");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
openFilePath(evt);
}
});
jTextArea1.setColumns(20);
jTextArea1.setFont(new java.awt.Font("宋体", 0, 20));
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 542, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void openFilePath(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openFilePath
// TODO add your handling code here:
int result = 0;
String path = null;
JFileChooser fileChooser = new JFileChooser();
FileSystemView fsv = FileSystemView.getFileSystemView(); //注意了,这里重要的一句
System.out.println(fsv.getHomeDirectory()); //得到桌面路径
fileChooser.setCurrentDirectory(fsv.getHomeDirectory());
fileChooser.setDialogTitle("选择文件路径");
fileChooser.setApproveButtonText("确定");
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
result = fileChooser.showOpenDialog(this);
if (JFileChooser.APPROVE_OPTION == result) {
path = fileChooser.getSelectedFile().getPath();
System.out.println("path: " + path);
}
if(path==null || path.equals("")){
return;
}
jTextArea1.setText("");
f = new File(path);
if (f.exists()) {
getList(f);
for (String filePath: pathList) {
File file = new File(filePath);
if (!file.exists()) {
break;
}
try {
String str = jTextArea1.getText();
String s = "文件名:" + file.getName() + "\n" + "文件大小:"+ getFileSize(file) + "Bit; "+ (float)getFileSize(file)/(float)1024/(float)1024+"MB"
+ApkUtil.getApkInfo(file.getPath()) + "\n\n";
jTextArea1.setText(s + str);
} catch (Exception ex) {
Logger.getLogger(MainTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
private void getList(File file){
if(file.isFile() && file.getName().endsWith(".apk")){
pathList.add(file.getPath());
}else{
File fileList[] = file.listFiles();
for(File f : fileList){
try {
getList(f);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
/**
* 获取指定文件大小
* @param f
* @return
* @throws Exception
*/
private long getFileSize(File file) throws Exception {
long size = 0;
if (file.exists()) {
FileInputStream fis = null;
fis = new FileInputStream(file);
size = fis.available();
} else {
file.createNewFile();
}
return size;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainTest().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextA

l_wKong
- 粉丝: 83
最新资源
- 实验一Linux基本操作实验研究分析报告.doc
- 大数据安全与隐私保护.docx
- 北京化工大学自动化专业卓越工程师培养技术方案.doc
- 上半年信息处理技术员网络直播培训.docx
- PLC安装环境.doc
- 试论网络思想政治教育的理论基础.docx
- 互联网+教育环境下基于智慧校园的高校教育信息化建设探究.docx
- 论4G通信工程技术的要点.docx
- Git高级技巧大全之深入探究基础教程
- NOIP2016初赛普及组C++题目及标准答案.doc
- 电子商城网站建设策划.doc
- 51单片机直流电机控制系统大学本科方案设计书.doc
- 财务公司行业信息化发展最佳实践研究.doc
- 大数据时代网络信息安全及防范措施.docx
- MATLAB课程设计方案研究报告(绝对完整).doc
- 土木工程C语言课程方案任务书.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



- 1
- 2
- 3
- 4
- 5
- 6
前往页