如何在文件系统中打开文件:通过链接

时间:2019-02-15 23:16:32

标签: javascript html5-filesystem

我已经使用FileSystem API创建了一个文件。我无法通过简单的链接打开它。但是,我可以打开将URL手动放置在浏览器中的页面(文件系统:http://localhost:8100/temporary/log.csv

我现在仅在google chrome上进行测试。

window.open("filesystem:http://localhost:8100/temporary/log.csv")

我希望它会在新窗口中打开。

更新: 通过使用window.URL.createObjectURL()解决了此问题。 因此链接将类似于blob:http://localhost:8100/7aa5685c-ca4f-485a-8bf8-d1c95e6257ab,该链接有效

2 个答案:

答案 0 :(得分:1)

如果您知道文件服务器在Web服务器的根文件夹中的位置(例如:d:\apache\www_root\temporary\),则将 csv 文件复制到此处。

完成后,您应该可以使用以下方法从Javascript中打开它:

window.open("http://localhost:8100/temporary/log.csv")

答案 1 :(得分:0)

同一问题。

由于该产品仅适用于Chrome,因此使用FileSystem API。

您如何将FileEntry转换为objectURL?

想通了

#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <fstream>
#include <algorithm>
#include <istream>
using namespace std;
class CStudentEmploy {
private:
    string m_strName;
    string m_strFacNum;
    int m_iMinutes;
public:
    CStudentEmploy() {
        m_strName = "Empty";
        m_strFacNum = "Empty";
        m_iMinutes = 0;
    }
    CStudentEmploy(string strname,string strfacnum,int minutes) {
        m_strName = strname;
        m_strFacNum = strfacnum;
        m_iMinutes = minutes;
    }
    CStudentEmploy(const CStudentEmploy &obj) {
        m_strName = obj.m_strName;
        m_strFacNum =obj.m_strFacNum;
        m_iMinutes =obj.m_iMinutes;
    }
    int get_m_iMinutes() {
        return m_iMinutes;
    }
    CStudentEmploy operator =(const CStudentEmploy &obj) {
        this->m_strName = obj.m_strName;
        this->m_strFacNum = obj.m_strFacNum;
        this->m_iMinutes = obj.m_iMinutes;
        return *this;
    }

    bool operator <(const CStudentEmploy &obj)const {
        return m_iMinutes<obj.m_iMinutes;
    }
    CStudentEmploy operator +(const CStudentEmploy &obj) {
        this->m_iMinutes += obj.m_iMinutes;
        return *this;
    }
    friend ostream& operator << (ostream& str, const CStudentEmploy &obj)
    {
        str << "\nIme: " << obj.m_strName<< "\nF Nomer: " << obj.m_strFacNum << "\nMinuti:" << obj.m_iMinutes << endl;
        return str;
    }

    friend istream& operator >> (istream& str,CStudentEmploy& obj)
    {
        str >> obj.m_strName >> obj.m_strFacNum >> obj.m_iMinutes;
        return str;
    }
};
class CAnalizeData:CStudentEmploy {
private:
    vector<CStudentEmploy*>m_vData;
public:
    CAnalizeData(const string &strFileName) {
        ifstream ifile(strFileName.data());
        copy(istream_iterator<CStudentEmploy*>(ifile), istream_iterator<CStudentEmploy*>(), back_inserter(m_vData));
    }
    void Write() {
        vector<CStudentEmploy*>::iterator it = m_vData.begin();
        while (it != m_vData.end())
        {
            cout << *it++;
        }
    }
    void Sort() {
        sort(m_vData.begin(), m_vData.end());
    }
    double calcMean() {
        double avg = 0;
        vector<CStudentEmploy*>::iterator it = m_vData.begin();
        for (it = m_vData.begin(); it != m_vData.end(); it++) {
            avg += (*it)->get_m_iMinutes();
        }
        cout << "Average minutes is:";
        return avg / m_vData.size();
    }
};
int main() {
    CAnalizeData AB("Test.txt");
    AB.Sort();
    AB.Write();
    cout << AB.calcMean();
    cout << endl;   system("pause");
    return 0;
}
相关问题