{"id":40459,"date":"2023-09-27T19:50:24","date_gmt":"2023-09-27T11:50:24","guid":{"rendered":"\/\/www.viralrail.com\/?p=40459"},"modified":"2023-09-27T19:50:24","modified_gmt":"2023-09-27T11:50:24","slug":"exrbdwj","status":"publish","type":"post","link":"\/\/www.viralrail.com\/blog\/40459.html","title":{"rendered":"Electron\u5199\u5165\u672c\u5730\u6587\u4ef6"},"content":{"rendered":"

  Electron\u662f\u4e00\u79cd\u7528\u4e8e\u6784\u5efa\u8de8\u5e73\u53f0\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u6e90\u5e93\uff0c\u5b83\u4f7f\u7528JavaScript\u3001HTML\u548cCSS\u7f16\u5199\uff0c\u5e76\u4f7f\u7528Node.js\u4f5c\u4e3a\u8fd0\u884c\u73af\u5883\u3002\u5b83\u53ef\u4ee5\u8ba9\u4f60\u4f7f\u7528JavaScript\u3001HTML\u548cCSS\u6765\u6784\u5efa\u684c\u9762\u5e94\u7528\uff0c\u800c\u65e0\u9700\u5b66\u4e60\u4efb\u4f55\u65b0\u7684\u8bed\u8a00\u6216\u6846\u67b6\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Electron\u5199\u5165\u672c\u5730\u6587\u4ef6\uff0c\u4ee5\u53ca\u5982\u4f55\u5728Electron\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u672c\u5730\u6587\u4ef6\u3002<\/p>\n

Electron\u5199\u5165\u672c\u5730\u6587\u4ef6<\/h2>\n

  Electron\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u5199\u5165\u672c\u5730\u6587\u4ef6\uff0c\u4f7f\u7528Node.js\u7684fs\u6a21\u5757\u3002fs\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7684API\uff0c\u53ef\u4ee5\u8ba9\u4f60\u8bfb\u53d6\u548c\u5199\u5165\u672c\u5730\u6587\u4ef6\u3002<\/p>\n

  \u8981\u5199\u5165\u672c\u5730\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528fs.writeFileSync()\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\uff1a\u6587\u4ef6\u8def\u5f84\u548c\u8981\u5199\u5165\u6587\u4ef6\u7684\u6570\u636e\u3002\u4f8b\u5982\uff1a<\/p>\n

  const fs = require('fs');<\/p>

  const data = 'Hello, World!';<\/p>

  fs.writeFileSync('\/path\/to\/file.txt', data);<\/p><\/pre>\n

  \u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u5b57\u7b26\u4e32\u201cHello, World!\u201d\u5199\u5165\u6587\u4ef6\/path\/to\/file.txt\u3002<\/p>\n

  \u5982\u679c\u8981\u5199\u5165\u7684\u6587\u4ef6\u4e0d\u5b58\u5728\uff0cfs.writeFileSync()\u4f1a\u81ea\u52a8\u521b\u5efa\u6587\u4ef6\uff0c\u5982\u679c\u6587\u4ef6\u5df2\u5b58\u5728\uff0c\u5219\u4f1a\u8986\u76d6\u539f\u6709\u5185\u5bb9\u3002<\/p>\n

\u5728Electron\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u672c\u5730\u6587\u4ef6<\/h2>\n

  \u5728Electron\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Node.js\u7684fs\u6a21\u5757\u6765\u8bfb\u53d6\u672c\u5730\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528fs.readFileSync()\u65b9\u6cd5\u8bfb\u53d6\u6587\u4ef6\uff1a<\/p>\n

  const fs = require('fs');<\/p>

  const data = fs.readFileSync('\/path\/to\/file.txt');<\/p>

  console.log(data.toString());<\/p><\/pre>\n

  \u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u8bfb\u53d6\u6587\u4ef6\/path\/to\/file.txt\uff0c\u5e76\u5c06\u6587\u4ef6\u5185\u5bb9\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u6253\u5370\u5230\u63a7\u5236\u53f0\u3002<\/p>\n

  \u5728Electron\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Node.js\u7684fs\u6a21\u5757\u6765\u8bfb\u5199\u672c\u5730\u6587\u4ef6\uff0c\u8fd9\u6837\u53ef\u4ee5\u8ba9\u4f60\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u66f4\u52a0\u5f3a\u5927\u3002<\/p>\n

\u603b\u7ed3<\/h2>\n

  \u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Electron\u5199\u5165\u672c\u5730\u6587\u4ef6\uff0c\u4ee5\u53ca\u5982\u4f55\u5728Electron\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u672c\u5730\u6587\u4ef6\u3002<\/strong>Electron\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u5199\u5165\u672c\u5730\u6587\u4ef6\uff0c\u4f7f\u7528Node.js\u7684fs\u6a21\u5757\uff0c\u53ef\u4ee5\u4f7f\u7528fs.writeFileSync()\u65b9\u6cd5\u5c06\u6570\u636e\u5199\u5165\u6587\u4ef6\uff0c\u800c\u5728Electron\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528fs.readFileSync()\u65b9\u6cd5\u8bfb\u53d6\u672c\u5730\u6587\u4ef6\u3002\u8fd9\u6837\u53ef\u4ee5\u8ba9\u4f60\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u66f4\u52a0\u5f3a\u5927\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

Electron\u662f\u4e00\u79cd\u7528\u4e8e\u6784\u5efa\u8de8\u5e73\u53f0\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u6e90\u5e93\uff0c\u5b83\u4f7f\u7528JavaScript\u3001HTML\u548cCSS\u7f16\u5199\uff0c\u5e76\u4f7f\u7528Node.js\u4f5c\u4e3a\u8fd0\u884c\u73af\u5883\u3002\u5b83\u53ef\u4ee5\u8ba9\u4f60\u4f7f\u7528JavaScr<\/p>\n","protected":false},"author":1,"featured_media":4132,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[36],"tags":[305],"class_list":["post-40459","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-dzjs"],"_links":{"self":[{"href":"\/\/www.viralrail.com\/wp-json\/wp\/v2\/posts\/40459"}],"collection":[{"href":"\/\/www.viralrail.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"\/\/www.viralrail.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/\/www.viralrail.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/\/www.viralrail.com\/wp-json\/wp\/v2\/comments?post=40459"}],"version-history":[{"count":0,"href":"\/\/www.viralrail.com\/wp-json\/wp\/v2\/posts\/40459\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"\/\/www.viralrail.com\/wp-json\/wp\/v2\/media\/4132"}],"wp:attachment":[{"href":"\/\/www.viralrail.com\/wp-json\/wp\/v2\/media?parent=40459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/\/www.viralrail.com\/wp-json\/wp\/v2\/categories?post=40459"},{"taxonomy":"post_tag","embeddable":true,"href":"\/\/www.viralrail.com\/wp-json\/wp\/v2\/tags?post=40459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}