• [AIR] 获取U盘,打开U盘


    示例:

    获取存储卷的方法:

    package com.controls
    {
        import flash.events.StorageVolumeChangeEvent;
        import flash.filesystem.StorageVolume;
        import flash.filesystem.StorageVolumeInfo;
    
        /**
         * @author Frost.Yen
         * @E-mail 871979853@qq.com
         * @create 2016-10-10 下午3:31:57
         *
         */
        public class StorageVolumeControl
        {
            
            public function StorageVolumeControl()
            {
                //监听外部设备连接和断开状态
                if (StorageVolumeInfo.isSupported)
                {
                    trace("平台支持 StorageVolumeInfo 类");
                    //卷装入;
                    StorageVolumeInfo.storageVolumeInfo.addEventListener(StorageVolumeChangeEvent.STORAGE_VOLUME_MOUNT, onVolumeMount);
                    //存储卷卸载;
                    StorageVolumeInfo.storageVolumeInfo.addEventListener(StorageVolumeChangeEvent.STORAGE_VOLUME_UNMOUNT, onVolumeUnmount);
                }
                else
                {
                    trace("平台不支持 StorageVolumeInfo 类");
                }
            }
            private function onVolumeMount(e:StorageVolumeChangeEvent):void
            {
                trace( e.storageVolume.name,"检测到可移动磁盘" );
                //trace( e.storageVolume.fileSystemType );
                //trace( e.storageVolume.isRemovable );
                //trace( e.storageVolume.isWritable );
                //trace( e.storageVolume.rootDirectory );
                //trace( e.storageVolume.rootDirectory.nativePath );
            }
            private function onVolumeUnmount(e:StorageVolumeChangeEvent):void
            {
                trace("卸载可移动磁盘" );
            }
            /**
             * 获取所有 存储卷对象StorageVolume
             * @return 
             * 
             */        
            public function getStorageVolumes():Vector.<StorageVolume>
            {
                var volumes:Vector.<StorageVolume >  = new Vector.<StorageVolume >;
                volumes = StorageVolumeInfo.storageVolumeInfo.getStorageVolumes();
                return volumes;
            }
            /**
             * 获取可以可删除的存储卷( 操作系统将存储卷视为可删除 (true) 还是不可删除 (false)。) 
             * @return 
             * 
             */        
            public function getRemovable():Vector.<StorageVolume>
            {
                var removable:Vector.<StorageVolume> = new Vector.<StorageVolume>();
                var volumes:Vector.<StorageVolume >= getStorageVolumes();
                for (var i:int = 0; i < volumes.length; i++)
                {
                    if (volumes[i].isRemovable)
                    {
                        trace(volumes[i].rootDirectory.nativePath);
                        removable.push(volumes[i]);
                    }
                }
                return removable;
            }
        }
    }

    打开第一个U盘:

    var volumes:Vector.<StorageVolume> = _storageVolume.getRemovable();
    if(volumes.length){
        var file2:File =new File(volumes[0].rootDirectory.nativePath);
        file2.openWithDefaultApplication();
    }
  • 相关阅读:
    链路的有效性检测 及 基于TCP的通信为什么需要RETRY
    python join
    协程
    python socket 选项
    Spring @Resource、@Autowired、@Qualifier的区别
    maven插件
    代码中的特殊注释
    AOP 底层技术比较
    关于Android开发中的证书和密钥等问题
    tomcat部署web项目的3中方法
  • 原文地址:https://www.cnblogs.com/frost-yen/p/6196621.html
Copyright © 2020-2023  润新知