如何将文本文件写入连接在USB中的智能手机闪存驱动器?

时间:2015-07-20 15:02:31

标签: c# .net winforms

问题在于,当我将智能手机连接到USB时,我在我的电脑资源管理器G3上看到我没有看到像C:D:E:F:G:

的新驱动器号

所以作为一个路径我怎么知道在哪里写文本文件?如何获取连接到USB的智能手机的闪存盘符号?

我现在尝试了这个:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace Write_to_flash_drive
{
    public partial class Form1 : Form
    {

        string pathtowrite = @"G3\Internal storage";

        public Form1()
        {
            InitializeComponent();

            StreamWriter w = new StreamWriter(pathtowrite + "\\test.txt");
            w.Write("test");
            w.Close();

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

得到例外:

  

无法找到路径的一部分'D:\ C-Sharp \写入闪存驱动器\写入闪存驱动器\写入闪存驱动器\ bin \ Debug \ G3 \内部存储\ test.txt'。

1 个答案:

答案 0 :(得分:1)

假设您的智能手机是LG G3,则在将其连接到USB端口时必须选择MTP协议:here is how

Windows将为您分配一个字母,这样您就可以将字母设置为路径并像在C#中一样编写文件。Example