标签: readfile

readRDS 无法在 R 中读入文件。是否有替代方案?

我正在尝试读取从此处下载的 RDS 文件:

https://github.com/jheng5/googleCharts/tree/master/inst/examples/bubble

但是,当我尝试通过以下方式将其加载到 RStudio 中时:

data<- readRDS('/Users/nathanf/shinyCharts/healthexp.rds')
Run Code Online (Sandbox Code Playgroud)

我收到错误:未知的输入格式。

我搜索并找到了 StackOverflow 上已发布的可能解决方案,但其中提到的解决方案不起作用。

不起作用: R 中的 readRDS(file)

请注意,我尝试在运行 Yosemite 的 Mac 上使用新安装的 R (3.2.1) 副本来执行此操作。

我在网上找到文章说 readRDS 功能现已失效。https://stat.ethz.ch/R-manual/R-devel/library/base/html/base-defunct.html

Sooooooo...最亲爱的社区,我该怎么办?是否有其他方法使用新函数读取 RDS 文件?

任何帮助将非常感激。

谢谢你,内森

r readfile

6
推荐指数
1
解决办法
1万
查看次数

同步ReadFile读取的字节数

假设我有 1Mb 文件,文件指针位于文件的开头。我调用同步ReadFile:

ReadFile(Handle, Buffer, 1024, Result, nil);
Run Code Online (Sandbox Code Playgroud)

调用成功,没有出现错误。结果值(读取的字节数)是否可能小于 1024(读取的字节数)?

我认为这对于磁盘文件来说是不可能的,我不确定ReadFile可以访问其他资源。在编写可以使用不同资源的通用代码时,我是否应该考虑上述情况?


为了避免哲学推测,我可以将问题重新表述如下:

同步 ReadFile 执行无错误,并且读取的字节数小于要读取的字节数。我可以确定达到 EOF 吗?

c delphi winapi readfile

5
推荐指数
1
解决办法
3758
查看次数

PHP Readfile 方法的安全问题

嘿。在 PHP 中使用该方法时有什么安全问题需要担心吗readfile?我想使用 readfile 方法来获取存储在各种第三方服务器上的文件的 URL。然后我将文件提供给用户。直观上,似乎存在风险,因为 URL 可以指向任何文件。另一方面,我仅使用该readfile方法(在处理一些与文件无关的数据之后),并且不确定这是否会允许任何恶意内容在我的服务器上执行。另外,根据手册,似乎如果我想使用带有 的 URL readfile,我需要启用fopen wrappers。谢谢。

php security fopen readfile

5
推荐指数
1
解决办法
3651
查看次数

串口通讯初始化

当时我们正在尝试为串行通信创建一个接口,以便能够与微处理器进行通信。

实际上 - 一切正常。几乎!为了能够与我们的控制器通信,我们需要与它同步。为此,我们编写一个字符串:"?0{SY}13!",然后控制器应回复"!0{SY}F5?"以接受同步请求。为此,我们使用一个writeData函数(有效 - 我们知道使用echo),然后我们使用 areadData来阅读答案。问题是,由于某种原因,它不会读取任何内容。虽然它返回1成功,但它读取的字符是恒定的" "(没有)。

现在是奇怪的部分 - 如果我们使用外部终端程序来初始化端口(如 putty),然后关闭程序,那么一切正常。它接受同步请求、回答(我们可以阅读它),然后我们可以做我们想做的一切。但是除非我们使用外部程序来初始化端口,否则它不起作用。

初始化接口的构造函数如下所示:

SerialIF::SerialIF(int baud, int byteSize, int stopBits, char* parity, int debug)
{
    string coutport = getPort();    
    wstring wideport;               
    debug_ = debug;                 //Debuglevel

    sync = false;                   //sync starts with false

    error = false;                  //Error false as beginnging

    //this is just for converting to the right type
    for (int i = 0; i < coutport.length(); i++) …
Run Code Online (Sandbox Code Playgroud)

c++ windows winapi serial-communication readfile

5
推荐指数
1
解决办法
2642
查看次数

python - 使用 win32file.ReadFile 读取文件

类似问题:

使用 win32file.ReadFile 从管道获取输出的正确方法是什么?

然而,我的问题在那个问题中没有得到回答。当我打电话

result, data = win32file.ReadFile(my_file, 4096, None)
Run Code Online (Sandbox Code Playgroud)

结果始终为 0,根据文档,这意味着成功:

The result is a tuple of (hr, string/PyOVERLAPPEDReadBuffer), where hr may be 0, 
ERROR_MORE_DATA or ERROR_IO_PENDING.
Run Code Online (Sandbox Code Playgroud)

即使我将缓冲区设置为 10 并且文件大得多,结果也是 0 并且数据是包含前 10 个字符的字符串。

result, buf = win32file.ReadFile(self._handle, 10, None)  
while result == winerror.ERROR_MORE_DATA:            
    result, data = win32file.ReadFile(self._handle, 2048, None)
    buf += data   
    print "Hi"
return result, buf
Run Code Online (Sandbox Code Playgroud)

即使文件明显包含更多数据,也永远不会打印“嗨”。我的问题是如何确保在不使用荒谬的大缓冲区的情况下读取整个文件?

python pywin32 readfile

5
推荐指数
1
解决办法
4074
查看次数

使用 WaitCommEvent 时 WriteFile 挂起应用程序

我遇到了使用事件驱动方法进行串行端口通信的 win32 编程问题。我将我的通信句柄创建为:

hComm = CreateFile(lpszCommName, GENERIC_READ | GENERIC_WRITE, 0,
    NULL, OPEN_EXISTING, 0, NULL);
Run Code Online (Sandbox Code Playgroud)

我将 CommTimeouts 设置为:

    commTimeout.ReadIntervalTimeout = MAXWORD;
    commTimeout.ReadTotalTimeoutConstant = 0;
    commTimeout.ReadTotalTimeoutMultiplier = 0;
    commTimeout.WriteTotalTimeoutConstant = 0;
    commTimeout.WriteTotalTimeoutMultiplier = 0;
Run Code Online (Sandbox Code Playgroud)

我为 ReadFile 创建了一个线程,如下所示:

SetCommMask(hComm, EV_RXCHAR);
while (isConnected)
{
    if (WaitCommEvent(hComm, &dwEvent, NULL)) //If i comment out this block my write file will work fine
    {
        ClearCommError(hComm, &dwError, &cs);
        if ((dwEvent & EV_RXCHAR) && cs.cbInQue)
        {
            if (!ReadFile(hComm, str, cs.cbInQue, &read_byte, NULL))
              /* Process error*/
            else if (read_byte)
                /* …
Run Code Online (Sandbox Code Playgroud)

c winapi serial-port writefile readfile

5
推荐指数
1
解决办法
1677
查看次数

在不知道编码的情况下使用Python读取文件

我想从文件夹(带有os.walk)读取所有文件并将它们转换为一种编码(UTF-8)。问题是这些文件没有相同的编码。它们可以是 UTF-8、带 BOM 的 UTF-8、UTF-16。

有没有办法在不知道这些文件的编码的情况下读取这些文件?

python encoding readfile python-3.x

5
推荐指数
1
解决办法
4338
查看次数

将 Node.js 对象设置为从文件读取的数据

我想从文件中读取数据并将其添加到存储在内存中的对象中。文件 text.txt 中的数据大致如下所示:

One: {title: 'One' ,
contributor: 'Fred',
summary: 'blah' ,
comments: 'words' },

Two: {title: 'Two' ,
contributor: 'Chris' ,
summary: 'blah blah i'm a blah' ,
comments: '' },
Run Code Online (Sandbox Code Playgroud)

我试图将其设置为一个空对象,如下所示:

var fs = require('fs');
var text = Object.create(null);
fs.readFile("./public/text.txt", "utf-8", function(error, data) {
  text = { data };
});
Run Code Online (Sandbox Code Playgroud)

然而,当我登录text到控制台时,它看起来像这样:

{ data: 'One: {title: \'One\' ,\ncontributor: \'Fred\',\nsummary: \'blah\' ,\ncomments: \'words\' },\n    \nTwo: {title: \'Two\' ,\ncontributor: \'Chris\' ,\nsummary: \'blah blah i\'m a blah\' ,\ncomments: \'\' },\n\n' …
Run Code Online (Sandbox Code Playgroud)

javascript object fs readfile node.js

5
推荐指数
1
解决办法
2894
查看次数

React Native 中的react-native-fs 库有其他可用的替代方案吗?

我正在 React Native 代码中读取大型 json 文件,但它给我带来了不可接受的性能损失。他们的文档中也提到了大文件的性能问题。

是否有任何替代方案可以帮助我从文档目录中读取文件而不影响性能?

readfile react-native

5
推荐指数
1
解决办法
6749
查看次数

使用 php 从服务器下载后 docx 文件已损坏

我正在尝试使用 php 从服务器下载 Word 文档(.docx)。不幸的是我得到的文件已损坏。我可以用 word 打开文档,但我收到这些恼人的消息(文件已损坏等)。这是我的代码:

$file = "documents/".$_POST["id_form"]."_document.docx";
$filename = $_POST["id_form"]."_document.docx";
header("Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document");
header("Content-Disposition: attachment; filename=".$filename);

readfile($file);
Run Code Online (Sandbox Code Playgroud)

感谢您的帮助!

更新解决方案

我得到了解决方案。我必须把ob_end_clean();在标题和出口之前;在 readfile($file) 之后。现在效果很好。

这是工作代码:

    $file = "documents/".$_POST["id_form"]."_document.docx";
    $filename = $_POST["id_form"]."_document.docx";                 
    ob_end_clean();
    header("Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document");
    header("Content-Disposition: attachment; filename=".$filename);
    readfile($file);
    exit;
Run Code Online (Sandbox Code Playgroud)

php download docx readfile

5
推荐指数
0
解决办法
1747
查看次数