我的控制台应用程序检查网络驱动器上是否存在文件,并在不存在时记录消息.今天我将我的应用程序部署到QA计算机,File.Exists()已经为存在的文件返回false.我通过Windows任务调度程序运行应用程序.当我从命令行运行它似乎工作正常.但不管怎样,我现在都不相信它.有没有人看过这种行为或有任何见解?:
Using System.IO;
private static void Main()
{
var fileName = @"x:\folder\file1.txt"; //be a network share
If (!File.Exists(fileName)
{
LogMessage("File is not on disk.");
}
else
{
LogMessage("File is on disk.");
}
}
Run Code Online (Sandbox Code Playgroud) 我的readfile方法有问题.我无法在文本文件中打印出数字值,但我的名字很好.
这就是我的文本文件中的所有内容:
Bob
10
12.00
Run Code Online (Sandbox Code Playgroud)
码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "iofunctions.h"
int readfile( struct account accarray[], int* numcust, char filename[])
{
/* variables */
FILE *inputFile;
char line[25];
char spaceEater[25];
char name[25]={"\0"};
int accountNum;
float money ;
inputFile = fopen("People_Info.txt", "r");
if(inputFile == NULL)
{
fprintf(stderr, "Sorry, I cannot open this file. Also it's empty.\n");
exit(1);
}
/*outer loop is to check if file is not null*/
while(!feof(inputFile))
{
/*while file has something*/
while(fscanf(inputFile,"%s %d …Run Code Online (Sandbox Code Playgroud) 我正在尝试做文件IO,我写了一个程序:
我正在尝试阅读的文本存储在名为input.txt的文件中.这是确切的文字......
I am a file.
This is a line.
This is the last line.
Run Code Online (Sandbox Code Playgroud)
这是我的功能,阅读该文件并打印出我想要的结果.
in1 = open("input.txt", 'r')
x=0
for line in in1:
print ('Line %d ' % (x)),
print ("(%d chars): " % (len(line))),
print (line),
x += 1
Run Code Online (Sandbox Code Playgroud)
我的终端输出应该是
Line 0 (12 chars): I am a file.
Line 1 (15 chars): This is a line.
Line 2 (22 chars): This is the last line.
Run Code Online (Sandbox Code Playgroud)
但我的实际终端输出是
Line 0 (13 …Run Code Online (Sandbox Code Playgroud) 尝试使用fstream在C++中读取文件.但是is_open()函数总是返回0结果而readline()不会读取任何内容.请参阅下面的代码段.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string line;
ifstream myfile("D:\xx\xx\xx\xx\testdata\task1.in.1");
if (myfile.is_open()) {
while (getline(myfile, line)) {
cout << line << '\n';
}
myfile.close();
}
else
cout << "Unable to open file";
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试组织保存和加载大小不一的数据.因此,保存文件需要存储多个(未知且每次不同数量)的动态数组.
这个MCVE中出现错误:
procedure TAnnMainF.Button6Click(Sender: TObject);
var
f: file;
ari, aro: array of double;
i, Count: word;
begin
SetLength(aro, random(5) + 1);
for i := 0 to High(aro) do
aro[i] := random(2001) / 2000 - 1;
AssignFile(f, 'c:\delme\1.txt');
ReWrite(f);
Count := Length(aro);
BlockWrite(f, Count, SizeOf(word));
BlockWrite(f, aro[0], SizeOf(double) * Count);
CloseFile(f);
Reset(f);
BlockRead(f, Count, SizeOf(word));
BlockRead(f, ari[0], SizeOf(double) * Count);
CloseFile(f);
end;
Run Code Online (Sandbox Code Playgroud)
此代码导致I/O错误998.我试图声明类型 TDoubleArray = array of Double;并ari在BlockRead中作为参数传递.SetLength(ari, Count)在我调用BlockRead之前我也尝试过没有任何成功.
我想在我当前用户的桌面文件夹上创建一个文件夹; 我一直收到拒绝访问的消息.我在IIS中的配置文件下有完整的写权限.
string activeDir = @"C:\Users\dmm\Desktop\";
string newPath = System.IO.Path.Combine(activeDir, "mySubDir");
System.IO.Directory.CreateDirectory(newPath);
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
我希望编写一个简短的bash脚本,它使用awk来调整三个文件的内容,并添加一个额外的行,其中一些文本作为第四行.例如:
档案1:
one.0
one.1
one.2
one.3
Run Code Online (Sandbox Code Playgroud)
文件2:
two.0
two.1
two.2
two.3
Run Code Online (Sandbox Code Playgroud)
档案3:
three.0
three.1
three.2
three.3
Run Code Online (Sandbox Code Playgroud)
期望的结果:
one.0
two.0
three.0
sometext
one.1
two.1
three.1
sometext
one.2
two.2
three.2
sometext
one.3
two.3
three.3
sometext
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我有一个myfile.mat包含3000x35大小数据的文件。当我将其加载到变量中时:
a = load('myfile.mat')
Run Code Online (Sandbox Code Playgroud)
它给出struct了大小1x1。我怎样才能得到确切的形式作为矩阵。这是必需的,因为我需要更改某些列值。
所以我似乎无法重定向输入,以便我的程序读取它.
它在赋值中说程序不应该打印任何东西以提示用户输入.由于必须从stdin中读取许多数字来测试程序,因此您需要使用INPUT REDIRECTION来读取文件中的输入.
我有这个主要功能:
int main(int argc, char const *argv[])
{
int arr[100];
for (int i = 0; i < SIZE; i++)
{
values[i] = 0;
hashMapLinear[i] = 0;
}
FILE* file = fopen("file_name.txt", "r");
int index = 0;
int k = 0;
while (!feof(file))
{
fscanf(file, "%d", &k);
arr[index] = k;
index++;
}
fclose(file);
file = fopen("file_name.txt", "r");
int i = 0;
fscanf(file, "%d", &i);
float size = i;
fscanf(file, "%d", &i);
int thresh_hold = i;
int load_factor = …Run Code Online (Sandbox Code Playgroud) 我尝试从tfrecords文件加载示例。我有一个类似的阅读器功能:
def read_record(filename_queue):
reader = tf.TFRecordReader()
key, record_string = reader.read(filename_queue)
features = {
"feature": tf.FixedLenFeature([], dtype=tf.string),
}
ex_dict = tf.parse_single_example(record_string, features)
ex_feature = tf.decode_raw(ex_dict["feature"], tf.float32)
return ex_feature
Run Code Online (Sandbox Code Playgroud)
但是之后
example_features = read_record(filename_queue)
values = sess.run({"features":example_features})
Run Code Online (Sandbox Code Playgroud)
停止并显示以下错误:
InvalidArgumentError:名称:,键:功能,索引:0。字节数!! =预期值。值大小:4096,但输出形状:[]由op u'ParseSingleExample / ParseExample / ParseExample'引起
有什么问题(我知道我可以提及实际尺寸,但我不想要这个)吗?