标签: file-io

使用随机访问文件而不是FIle Writer和FileReader有什么好处?

我理解课程FileWriterFile Reader.

我想知道这个班级RandomAccessFileFileWriterFileReader.相比.

java file-io

-1
推荐指数
1
解决办法
1895
查看次数

perl从两个文件中读取相同的行

我有两个具有相同行数的文件,每行包含数值列.

文件示例 A

1 2 3 4
2 3 4 5
Run Code Online (Sandbox Code Playgroud)

文件示例 B

7 8 9 0
6 7 8 9
Run Code Online (Sandbox Code Playgroud)

我想从这两个文件中求和相应行的值,并将结果写入输出文件.

预期产量:

8 10 12 4
8 10 12 14
Run Code Online (Sandbox Code Playgroud)

perl file-io loops

-1
推荐指数
1
解决办法
5299
查看次数

无法在C中显示文件的内容

我试图读取一个名为的文件的内容,pp.txt并在命令行上显示它的内容.我的代码是:

#include<stdio.h>
#include<stdlib.h>
int main()
{

FILE *f;
float x;


f=fopen("pp.txt", "r");

if((f = fopen("pp.txt", "r")) == NULL)
{
fprintf(stderr, "Sorry! Can't read %s\n", "TEST1.txt");
}

else
{
printf("File opened successfully!\n");
}

fscanf(f, " %f", &x);

if (fscanf(f, " %f ", &x) != 1) {
fprintf(stderr, "File read failed\n");
return EXIT_FAILURE;
}

else
{
printf("The contents of file are: %f \n", x);
}


fclose(f);

return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译后我得到了File opened successfully!File read failed.我的内容pp.txt是34.5.谁能告诉我哪里出错了?

c file-io file

-1
推荐指数
1
解决办法
134
查看次数

C#/ XML读取XML文件不起作用

我想读取XML文件并保存InnerText-Strings,但它会因SystemNullReference错误而崩溃.我认为我读它的方式是错误的,但我不确定.

XML的文件:

<?xml version="1.0" encoding="Windows-1252" standalone="no"?>
<schema>
  <Hintergrund>#FFFFFFFF</Hintergrund>
  <Zahlen>#FFFFFFFF</Zahlen>
  <Text>#FFFFFFFF</Text>
  <Zeichenketten>#FFFFFFFF</Zeichenketten>
  <Tags>#FF000000</Tags>
  <Direktiven>#FF000000</Direktiven>
  <Ausdruecke>#FF000000</Ausdruecke>
  <Initialisierer>#FF000000</Initialisierer>
  <Modifizierer>#FF000000</Modifizierer>
  <Booleanische>#FF000000</Booleanische>
  <Operator>#FF000000</Operator>
  <Kommentare>#FF000000</Kommentare>
</schema>
Run Code Online (Sandbox Code Playgroud)

读:

foreach (XmlNode node in doc.SelectNodes("/schema/*"))
{
    switch (node.Name)
    {
        case "Hintergrund":
            colorBG = (Color)ColorConverter.ConvertFromString(node["Hintergrund"].InnerText);
            break;
        case "Zahlen":
            colorNumbers = (Color)ColorConverter.ConvertFromString(node["Zahlen"].InnerText);
            break;
        case "Text":
            colorText = (Color)ColorConverter.ConvertFromString(node["Text"].InnerText);
            break;
        case "Zeichenketten":
            colorStrings = (Color)ColorConverter.ConvertFromString(node["Zeichenketten"].InnerText);
            break;
        case "Tags":
            colorTags = (Color)ColorConverter.ConvertFromString(node["Tags"].InnerText);
            break;
        case "Direktiven":
            colorDirectives = (Color)ColorConverter.ConvertFromString(node["Direktiven"].InnerText);
            break;
        case "Ausdruecke":
            colorStatements = (Color)ColorConverter.ConvertFromString(node["Ausdruecke"].InnerText);
            break;
        case "Initialisierer":
            colorInitial = (Color)ColorConverter.ConvertFromString(node["Initialisierer"].InnerText);
            break;
        case "Modifizierer": …
Run Code Online (Sandbox Code Playgroud)

.net c# xml wpf file-io

-1
推荐指数
1
解决办法
107
查看次数

如何从python中的url请求将unicode文件(jpg)写入另一个文件

我试图.jpg使用requestspython中的模块从URL 下载文件.这是我试过的.没有错误.但是我无法打开输出文件.

>>> import requests
>>> l = requests.get("http://www.mosta2bal.com/vb/imgcache/2/9086screen.jpg")
>>> l
<Response [200]>
>>> l.text
u'\ufffd\ufffd\ufffd\ufffd\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\ufffd\ufffd\x12EExif\x00\x00MM\x00*\x00\x00\x00\x08\x00\x07\x01\x12\x00\x03\x......long text
>>> l.encoding
>>> import codecs
>>> f = codecs.open('out.jpg', mode="w", encoding="utf-8")
>>> f.write(l.text)
Run Code Online (Sandbox Code Playgroud)

python unicode file-io python-requests

-1
推荐指数
1
解决办法
961
查看次数

用C++库替换标准的cstdio

我想要一个功能,当我的应用程序崩溃时,已写入的日志保存在日志文件中.但是使用fopen()/fwrite()from cstdio库似乎不会这样做.因此,当我的应用程序崩溃时,日志文件为0KB.我想知道是否有任何文件处理库可以做到这一点?例如Boost?

c++ file-io windows-7

-1
推荐指数
1
解决办法
70
查看次数

写入文件建议

这是我的代码:

import random

ch1=input("Please enter the name of your first character ")
strch1=(((random.randint(1,12)//(random.randint(1,4))))+10)
sklch1=(((random.randint(1,12)//(random.randint(1,4))))+10)
print("The strength value of "+ch1+" is:")
print (strch1)
print("and the skill value of "+ch1+" is:")
print (sklch1)

ch2=input("Please enter the name of your second character ")
strch2=(((random.randint(1,12)//(random.randint(1,4))))+10)
sklch2=(((random.randint(1,12)//(random.randint(1,4))))+10)
print("The strength value of "+ch2+" is:")
print (strch2)
print("and the skill value of "+ch2+" is:")
print (sklch2)

myFile = open("CharacterSkillAttributes.txt", "wt")

myFile.write("The attributes of "+ch1+" are: /n")
myFile.write("Strength: "+strch1+"/n")
myFile.write("Skill: "+sklch1+"/n")

myFile.write("The attributes of "+ch2+" are: /n")
myFile.write("Strength: …
Run Code Online (Sandbox Code Playgroud)

python file-io

-1
推荐指数
1
解决办法
143
查看次数

-1
推荐指数
1
解决办法
4488
查看次数

是否有更好的(更pythonic)方式将文件内容写入列表?

我目前正在使用以下语句将文件的每一行写入列表

try:
  list = []
  with open(file, 'r') as f:
    for l in f.readlines():
      list.append(l)
except:
  ...
Run Code Online (Sandbox Code Playgroud)

虽然它工作得很好,我想知道是否有更多的pythonic方式来做到这一点?

编辑: 使用建议的更新

try:
  my_list = []
  with open(file, 'r') as f:
    my_list = f.readlines()
except IOError:
  ...
Run Code Online (Sandbox Code Playgroud)

python file-io

-1
推荐指数
1
解决办法
138
查看次数

Python错误TypeError:函数只需1个参数(给定5个)

Traceback (most recent call last):
  File "wdd.py", line 164, in <module>
    file.write("temperature is ", temperature, "wet is ", humidity, "%\n")
TypeError: function takes exactly 1 argument (5 given)
Run Code Online (Sandbox Code Playgroud)

蟒蛇:

 # -*- coding: utf-8 -*-
"""
Created on Sun Jan 26 14:24:43 2014

@author: pi
"""
import smtplib
import RPi.GPIO as gpio
import time
gpio.setwarnings(False)
gpio.setmode(gpio.BOARD)
time.sleep(1)
data=[]
def delay(i): #20*i usdelay
    a=0
    for j in range(i):
        a+1
j=0
#start work
gpio.setup(7,gpio.OUT)
#gpio.output(12,gpio.HIGH)
#delay(10)
gpio.output(7,gpio.LOW)
time.sleep(0.02)
gpio.output(7,gpio.HIGH)
i=1
i=1

#wait to …
Run Code Online (Sandbox Code Playgroud)

python file-io python-2.7

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

标签 统计

file-io ×10

python ×4

.net ×1

android ×1

c ×1

c# ×1

c++ ×1

file ×1

java ×1

jsonobject ×1

loops ×1

perl ×1

python-2.7 ×1

python-requests ×1

unicode ×1

windows-7 ×1

wpf ×1

xml ×1