为什么我只能读取文件的前几个字节?

huangapple go评论50阅读模式
英文:

Why am I only able to read the first couple bytes of this file?

问题

Internetizens, this little program returns the first two characters out of the file I specified.
This is surprising to me, as the source file contains a few hundred lines of text.
What am I doing wrong? Can someone wiser spot my error please? Thank you! 为什么我只能读取文件的前几个字节?

-- This script will import to-dos and notes into Things from a plaintext file.
-- To run the script, click the green "Run" button in the toolbar above.
-- source:  https://culturedcode.com/things/support/articles/2803555/#import-from-a-plain-text-file
set unixPath to "/Volumes/2_TB_SSD_external/Projects_2TB/computers-and-geekery/projects and languages/Obsidian development/wealthyvault/bin/logs/things-commit.db"
-- set text_file to (open for access (POSIX file unixPath))

set text item delimiters to tab
set database_text to (read POSIX file unixPath as «class utf8»)
set numparagraphs to (count paragraphs of database_text)
return database_text
英文:

Internetizens, this little program returns the first two characters out of the file I specified.
This is surprising to me, as the source file contains a few hundred lines of text.
What am I doing wrong? Can someone wiser spot my error please? Thank you! 为什么我只能读取文件的前几个字节?

-- This script will import to-dos and notes into Things from a plaintext file.
-- To run the script, click the green "Run" button in the toolbar above.
-- source:  https://culturedcode.com/things/support/articles/2803555/#import-from-a-plain-text-file
set unixPath to "/Volumes/2_TB_SSD_external/Projects_2TB/computers-and-geekery/projects and languages/Obsidian development/wealthyvault/bin/logs/things-commit.db"
-- set text_file to (open for access (POSIX file unixPath))

set text item delimiters to tab
set database_text to (read POSIX file unixPath as «class utf8»)
set numparagraphs to (count paragraphs of database_text)
return database_text

答案1

得分: 0

我能够通过将<<utf8>>更改为string来解决我的问题:

set database_text to (read POSIX file unixPath as string)

不知道为什么,但这解决了问题。

英文:

I was able to solve my problem by changing <<utf8>> to string:

set database_text to (read POSIX file unixPath as «class utf8»)

became

set database_text to (read POSIX file unixPath as string)

I have no idea why, but this fixed the issue.

huangapple
  • 本文由 发表于 2023年3月31日 21:38:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75899196.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定