标签: file-io

写入文件没有\"符号haskell

例如需要这个文本来写一个文件:

This is some simple text "it's quote", test test

writeFile :: FilePath -> String -> IO ()用来写文件,但是当我尝试在文件中写这个字符串时,在文件中我看到:

This is some simple text \"it\'s quote\", test test

如何删除\符号,我只需要在我的文本文件中"没有\".

谢谢.

file-io haskell file

0
推荐指数
1
解决办法
289
查看次数

为什么找不到或打开我的文件?

我在.bin\Debug文件夹中添加了一个.txt文件,我试图打开它并像这样读取它:

using (StreamReader reader = File.OpenText("Credentials.txt")) {
    string line = null;
    do {
        line = reader.ReadLine();
        if (line.Contains("host=")) {
    . . .
Run Code Online (Sandbox Code Playgroud)

但是,虽然文件在那里,当我到达"ReadLine()"行时,它会停止在其轨道中:

System.NullReferenceException未处理Message = Object引用未设置为对象的实例.

UPDATE

我不得不将它从" do...while (line != null);" 更改为" while (! reader.EndOfStream)"

c# file-io nullreferenceexception winforms

0
推荐指数
1
解决办法
161
查看次数

StringBuilder可能出现内存泄漏?

我使用a StringBuilder来创建一个File对象,但我也用它来查看该文件所在的目录是否存在:

StringBuilder sbFile = new StringBuilder();
sbFile.append("/home/logs/");

File oFile = new File(sbFile.toString());

if(!oFile.exists())
    oFile.mkdir();

sbFile.append("MyLogFile.log");

oFile = new File(sbFile.toString());
Run Code Online (Sandbox Code Playgroud)

但我担心oFile在字符串生成器(/home/logs/vs /home/logs/MyLogFile.log)的两个不同"版本"上重用相同的引用会产生内存泄漏.如果是这样,我该怎么写这个呢?

java file-io memory-leaks

0
推荐指数
1
解决办法
1989
查看次数

为什么file.read()不读取第一行?

我不知道为什么,但是当我尝试用file.read()读取文件时,Python无法识别文件的第一行..这是一个解释器错误,或者这是我的错?

你有一份程序副本(显示阅读结果):http://pastebin.ubuntu.com/1032832/

这是导致问题的代码:

if wfile.readline() != "#! /usr/bin/env python\n":
    before = wfile.read()
    wfile.seek(0)
    wfile.write('#! /usr/bin/env python\n' + before)
    wfile.close()
    os.chmod(file, 777)
Run Code Online (Sandbox Code Playgroud)

我用于测试的Python版本是用于iOS的Python 2.5.1(Cydia端口).我的设备是iPad 2.

python file-io python-2.5

0
推荐指数
1
解决办法
1272
查看次数

C#确定文本文件名

我怎么能改变它来确定其目录本身的文本文件?

string[] file = new string[] {
    "abc",
    "def",
    "file3"};
var files = (UInt16)file.Length;
for (UInt16 n = 0; n < files; n++)
{
    var streamReader =
        new System.IO.StreamReader(
            file[n] + ".txt");
    ...
    streamReader.Close();
    ...
}
Run Code Online (Sandbox Code Playgroud)

c# file-io file

0
推荐指数
1
解决办法
146
查看次数

在java中快速解析文本文件

我有许多文本文件,它们是固定的,重复的格式,如:

Q 32,0 16
q 27
b 21
I 0
P 1
d 0
m 31,0
Q 48,0 16
q 27
b 2
I 2
P 1
d 0
m 31,0
.
.
.
Run Code Online (Sandbox Code Playgroud)

我想用Java解析它们.我想知道的是解析这样一个文本文件的最快方法.如果这有助于提高性能,我可以更改文本文件的输出格式,因为这里唯一的要求是解析速度.我也可以使用外部库.

java file-io parsing text-files

0
推荐指数
1
解决办法
2014
查看次数

在asp.net中删除桌面文件c#

我想要一个解决方案,我想删除一个文件,使用asp.net c#驻留在我的桌面,我使用下面的代码:

try 
{
    FileInfo TheFile = new FileInfo(MapPath(".") + "\\" + FileNameTextBox.Text);

    if (TheFile.Exists)
    {
        File.Delete(MapPath(".") + "\\" + FileNameTextBox.Text);
    }
    else
    {
        throw new FileNotFoundException();
    }
}
catch (FileNotFoundException ex)
{
    lblStatus.Text += ex.Message;
}
catch (Exception ex)
{
    lblStatus.Text += ex.Message;
}
Run Code Online (Sandbox Code Playgroud)

但它总是说无法找到文件位置,请提前帮助我谢谢

c# asp.net file-io

0
推荐指数
1
解决办法
251
查看次数

使用python将整数转换/连接到strying

我正在尝试从文本文件中读取最后一行.每行以数字开头,因此下次插入某些内容时,新数字将增加1.

例如,这将是一个典型的文件

1. Something here          date
2. Something else here     date
#next entry would be  "3.   something    date"
Run Code Online (Sandbox Code Playgroud)

如果文件为空,我可以输入一个没有问题的条目.但是,当已经有条目时,我收到以下错误

LastItemNum = lineList[-1][0:1] +1 #finds the last item's number
TypeError: cannon concatenate 'str' and 'int objects
Run Code Online (Sandbox Code Playgroud)

这是我的功能代码

 def AddToDo(self): 
    FILE = open(ToDo.filename,"a+") #open file for appending and reading
    FileLines = FILE.readlines() #read the lines in the file
    if os.path.getsize("EnteredInfo.dat") == 0: #if there is nothing, set the number to 1
        LastItemNum = "1"
    else:
        LastItemNum = FileLines[-1][0:1] + 1 #finds the …
Run Code Online (Sandbox Code Playgroud)

python file-io

0
推荐指数
1
解决办法
84
查看次数

在C linux中打开文件

我正在使用C打开文件进行阅读.我有这个代码:

fp = fopen("./settings.cfg","r");
if (fp != NULL)
    printf("OK");
else
    printf("ERROR");
Run Code Online (Sandbox Code Playgroud)

但我总是得到一个错误.

该文件位于可执行文件所在的文件夹中.我试过只写"settings.cfg".可能是什么问题?

c linux file-io

0
推荐指数
1
解决办法
7931
查看次数

在c ++中读取和写入vector <bool>到一个文件

我有一个矢量,其大小可能非常大(100万个元素).我将向量的内容写为文件作为字节值.我无法弄清楚如何将字节值读回到向量中.

这是代码:

#include <fstream>
#include <vector>
#include <iterator>
#include <iostream>
using namespace std;

int main()
{
  // Filling a vector with values
  std::vector<bool> ve;
  ve.push_back(true);
  ve.push_back(false);
  ve.push_back(true);
  ve.push_back(false);
  ve.push_back(true);
  // Printing the values of the vector
  for(unsigned int i = 0; i < ve.size(); i++)
      cout << ve.at(i) << ".";
  cout << endl;

  // Writing the vector contents to a file
  const char* file_name = "abc.txt";
  ofstream outfile(file_name, ios::out | ios::binary);
  outfile.write((const char*)&(ve[0]), ve.size());
  outfile.close();
  // Reading the file and …
Run Code Online (Sandbox Code Playgroud)

c++ file-io vector

0
推荐指数
1
解决办法
4118
查看次数