标签: file-io

InputStream read(byte [] b,int off,int len) - 删除文件的其余部分?

这是我今天早上在这里提出的一个问题的延伸,所以如果你认为你之前看过这个代码,请不要忽视:D

for (String name : filenames) {
FileInputStream in = new FileInputStream(input.readUTF());
    int byteCounter = 0;
    int rowCounter = 0;
    long bufferCounter = 0;
    byte[] b = new byte[10];
    int read;

    //in.skip(10);
    //while((read = in.read()) != -1){
    while((read = in.read(b, 0, 10)) != -1){
        byteCounter ++;
        if (byteCounter != 1000){
            if (rowCounter == 1){
                System.out.println("\n");
                rowCounter = 0;
            }
        System.out.print(org.apache.commons.codec.binary.Hex.encodeHexString(b));
            bufferCounter ++;
            rowCounter ++;
        }else{
                byteCounter = 0;
                try{
                    Thread.sleep(200);
                }catch(InterruptedException e) {
                }
        }
    }
    System.out.println("\n"+"================"+"\n");
}
Run Code Online (Sandbox Code Playgroud)

嗨,经过几个小时的努力才能得到这个代码,我几乎完成了我正在处理的特定组件.该程序接收一个指定的文件,并应该将该文件的前10个字节转换为Hex.一旦它获取了该文件的前10个字节,它应该停止并移动到下一个指定的文件.目前,它占用整个文件并将其分成多个10字节"块"然后打印出来.换句话说,它在我认为读取的前10个字节之后没有停止(byte [] …

java file-io hex inputstream file

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

file_get_contents在现有可读文件上返回false

好吧,我开始讨厌PHP了.我有一个文件,它是完全可读的(is_readable返回true),具有777权限,通常由fopen打开,但file_get_contents返回false.代码如下:

<?php
error_reporting(-1);
$handle = fopen("tres.txt","w+");
try{
$cnt = file_get_contents("/var/www/tres.txt");
}
catch(Exception $err){ echo $err->getMessage(); }
if ($handle) echo "Allright!", "<br />";
if ($cnt) echo "Good";
if(is_readable("/var/www/tres.txt")) echo " Is";
?>
Run Code Online (Sandbox Code Playgroud)

即使我打开了我知道的所有错误报告选项,也没有发现任何错误,这让我很生气.将文件路径更改为"tres.txt"的"./tres.txt"也没有任何效果.问题可能在哪里?

PS它运行在PHP5和apache2上.

php apache file-io

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

读取属于其他iOS应用程序的文件

我目前正在为iOS编写备份应用程序,我希望有一些选项让用户备份应用程序数据(其他应用程序的文档等),联系人,Safari书签以及所有有趣的东西.

我想知道这是否可能,我是怎么做的,以及这些文件的存储位置,最重要的是,如果Apple实际允许这样做.我读完了他们的文档,我没有看到任何反对它的东西.

backup file-io ios

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

从文件中读取值时,垃圾附加到输出

我是C++文件io的新手,所以前几天我决定编写一个小程序,只读取一个UTF-8编码的字符串和一个二进制文件中的配对浮点数.模式是字符串浮点数,没有额外的数据或对之间的间距.编辑我已根据几个答案修改了代码.但是,输出保持不变("RoommateAp 0");

string readString (ifstream* file)
{
    //Get the length of the upcoming string
    uint16_t stringSize = 0;
    file->read(reinterpret_cast<char*>(&stringSize), sizeof(char) * 2);

    //Now that we know how long buffer should be, initialize it
    char* buffer = new char[stringSize + 1];
    buffer[stringSize] = '\0';

    //Read in a number of chars equal to stringSize
    file->read(buffer, stringSize);
    //Build a string out of the data
    string result = buffer;

    delete[] buffer;
    return result;
}

float readFloat (ifstream* file)
{
    float buffer = …
Run Code Online (Sandbox Code Playgroud)

c++ file-io stream

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

使用ASP或PHP检查2个目录中是否存在文件

我正在寻找一种方法来比较2个目录,看看两个文件是否存在.我想要做的是删除其中一个目录中的文件(如果两个目录中都存在).

我可以使用ASPPHP.

例:

/devices/1001
/devices/1002
/devices/1003
/devices/1004
/devices/1005

/disabled/1001
/disabled/1002
/disabled/1003
Run Code Online (Sandbox Code Playgroud)

因此,由于1001, 1002, 1003存在/ disabled /,我想从/ devices /中删除它们,只留1004, 1005/ devices /中.

file-io

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

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

用C++打开文件

我试图用我的名字打开存储在我的驱动器上的文件test.txt.我遇到了很多错误.我是C++文件的新手.请帮助我谢谢.//在文本文件上书写

#include <iostream>
#include <fstream>
using namespace std; 
int main ()
 {
    ofstream mystream;
    mystream.open("C:\\test",ios::in||ios::out);
        /*Check if the file is opened properly*/
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ file-io compiler-errors

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

.startswith not working

在我的程序中,我有一个文件,然后我读取for循环中的所有行,检查每一行的开头.然后将每一行添加为变量.这里有40多行,它们几乎都是一样的但是其中一个elif语句并没有返回真实的.startswith无效.无论如何这里的文件内容基本上是一堆保存的信息fN将是我保存的变量,john将是我想要的.所以这个方法就是这样做的,或者它是假设的

fN:john
fP:1
fE:father email
mN:mother name
mP:1
mE:mother email @ bomg.com
a:1233 adress lane
c:city
s:state
zC:1234534
hP:(1928)phone-1123
cP:1113333
eN:emergancy
eNu:number
c1N:cluubiie 1
c1G:1st
c1B:1-23-34
c2N:clubbie 2
c2G:grade 2
c2B:birth 2
c3N:clubb 3 
c3G:grade 3
c3B:birth 3
Run Code Online (Sandbox Code Playgroud)

方法

def fillWindow(self,student):
    global fileDirectory
    location = os.path.join(fileDirectory, student + '.txt')
    file = open(location, 'r')

    for line in file.xreadlines():
        if line.startswith('fN'):
            fN = line.split(':')[1]
        elif line.startswith('fP'):
            fP = line.split(':')[1]
        elif line.startswith('fE'):
            fE = line.split(':')[1]
        elif line.startswith('mN'):
            mN = line.split(':')[1]
        elif line.startswith('mP'):
            mP …
Run Code Online (Sandbox Code Playgroud)

python file-io for-loop if-statement

0
推荐指数
2
解决办法
1591
查看次数

如何在php中读取11mb文本文件?

我用php读了11mb文本文件:

$data_array = array();

$counter = 0;        

while(!feof($fh))  {

    $buffer = fgets($fh, 4096);

    $data_array[$counter] = $buffer;

    $counter++;
}
Run Code Online (Sandbox Code Playgroud)

然后我想使用implode函数将所有变为一个变量.

$data = implode("",$data_array); 
Run Code Online (Sandbox Code Playgroud)

但脚本什么也没做.如果我在循环期间尝试将数据存储到一个变量中,则需要很长时间.
还有其他方法如何做到这一点?我需要在php中的一个变量中有来自11mb textfile的数据.

php file-io

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

Perl,从两个文件中读取并写入第三个文件

我无法让我的程序工作.基本上,我从两个文件读入,然后将数据写入一个.任何人都可以指出问题是什么?我一直在尝试写入文件的print OUT语句中获得有关实例化的错误.这是我的代码:

print "Please input file name \n";
$infile=<DATA>;
$infile2=<DATA>;

open IN, "$infile";
open JUNK, "$infile2";
open OUT, '>' ,'convertedback.txt';

$line = <IN>;
$line2 = <JUNK>;

#pull first line from sample (name 1)
print OUT "$line";
$line =<IN>;
#pull sequence line from FASTQ
print OUT "$line";
#pull line from quality file *2
print OUT "$line2";
$line2 =<JUNK>;
print OUT "$line2";

#Repeat until EOF
while($line =<IN>) {#for lines 5 to end

#Build Line 1
print "line 1 inf (name) is\n";
print …
Run Code Online (Sandbox Code Playgroud)

perl file-io

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

标签 统计

file-io ×10

c++ ×2

java ×2

php ×2

apache ×1

backup ×1

compiler-errors ×1

file ×1

for-loop ×1

hex ×1

if-statement ×1

inputstream ×1

ios ×1

perl ×1

python ×1

stream ×1