标签: file-io

如何使用JavaScript从服务器读取文本文件?

在服务器上,有一个文本文件.在客户端上使用JavaScript,我希望能够读取此文件并进行处理.无法更改服务器上文件的格式.

如何将文件的内容转换为JavaScript变量,以便进行此处理?文件的大小最大可达3.5 MB,但它可以很容易地处理成100行(1行是50-100个字符串).

该文件的所有内容都不应对用户可见; 他将看到文件中数据处理的结果.

javascript ajax file-io

34
推荐指数
5
解决办法
13万
查看次数

c#连续读取文件

我想像GNU尾部一样连续读取文件"-f"param.我需要它来实时读取日志文件.做正确的方法是什么?

c# file-io

33
推荐指数
4
解决办法
2万
查看次数

使用进度条进行文件复制

我用过这段代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;

namespace WindowsApplication1 {
  public partial class Form1 : Form {
    // Class to report progress
    private class UIProgress {
      public UIProgress(string name_, long bytes_, long maxbytes_) {
        name = name_; bytes = bytes_; maxbytes = maxbytes_;
      }
      public string name;
      public long bytes;
      public long maxbytes;
    }
    // Class to report exception {
    private class UIError {
      public UIError(Exception ex, string path_) {
        msg = ex.Message; path = path_; …
Run Code Online (Sandbox Code Playgroud)

c# file-io backgroundworker file-copying progress-bar

33
推荐指数
4
解决办法
8万
查看次数

如何在python中加载文件中的数据,进行单元测试?

我写了一个专门的HTML解析器,我想用我下载的几个示例网页进行单元测试.

在Java中,我使用了类资源,将数据加载到单元测试中,而不必依赖它们在文件系统的特定路径上.有没有办法在Python中执行此操作?

我找到了doctest.testfile()函数,但这似乎是doctests特有的.我想获得一个特定HTML文件的文件句柄,该文件与当前模块相关.

在此先感谢您的任何建议!

python file-io unit-testing

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

如何创建文件中每个单词的频率列表?

我有这样一个文件:

This is a file with many words.
Some of the words appear more than once.
Some of the words only appear one time.
Run Code Online (Sandbox Code Playgroud)

我想生成一个两列列表.第一列显示出现的单词,第二列显示出现的频率,例如:

this@1
is@1
a@1
file@1
with@1
many@1
words3
some@2
of@2
the@2
only@1
appear@2
more@1
than@1
one@1
once@1
time@1 
Run Code Online (Sandbox Code Playgroud)
  • 为了使这项工作更简单,在处理列表之前,我将删除所有标点符号,并将所有文本更改为小写字母.
  • 除非有一个简单的解决方案,words并且word可以算作两个单独的单词.

到目前为止,我有这个:

sed -i "s/ /\n/g" ./file1.txt # put all words on a new line
while read line
do
     count="$(grep -c $line file1.txt)"
     echo $line"@"$count >> file2.txt # add word and frequency to …
Run Code Online (Sandbox Code Playgroud)

bash file-io grep sed

33
推荐指数
5
解决办法
5万
查看次数

解析apache日志文件

我刚刚开始学习Python,并希望阅读Apache日志文件并将每行的部分内容放入不同的列表中.

来自文件的行

172.16.0.3 - - [25/Sep/2002:14:04:19 +0200]"GET/HTTP/1.1"401 - """Mozilla/5.0(X11; U; Linux i686; en-US; rv:1.1 )Gecko/20020827"

根据Apache网站的格式是

%h%l%u%t \"%r \"%> s%b \"%{Referer} i \"\"%{User-Agent} i \

我能够打开文件并按原样读取它,但我不知道如何以该格式读取它,所以我可以将每个部分放在一个列表中.

python file-io

33
推荐指数
5
解决办法
5万
查看次数

Java Files.write NoSuchFileException

我正在尝试使用Files.write()方法将一些文本写入文件.

byte[] contents = project.getCode().getBytes(StandardCharsets.UTF_8);

try {
    Files.write(project.getFilePath(), contents, StandardOpenOption.CREATE);
} catch (IOException ex) {
    ex.printStackTrace();
    return;
}
Run Code Online (Sandbox Code Playgroud)

根据API,如果文件不存在,它将被创建然后写入.

但是,我明白了:

java.nio.file.NoSuchFileException: C:\Users\Administrator\Desktop\work\Default.txt
    at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
    at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
    at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
    at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(Unknown Source)
    at java.nio.file.spi.FileSystemProvider.newOutputStream(Unknown Source)
    at java.nio.file.Files.newOutputStream(Unknown Source)
    at java.nio.file.Files.write(Unknown Source)
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

java file-io file filenotfoundexception

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

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

PHP创建随机tmp文件并获取其完整路径

我这样做之后:

$temp = tmpfile();
fwrite($temp, "writing to tempfile");
Run Code Online (Sandbox Code Playgroud)

我想获得已创建$temp文件的完整路径tmpfile.

我需要做些什么来获取这些信息?

php file-io file path

33
推荐指数
2
解决办法
3万
查看次数

PHP:删除文件夹的最简单方法(包括其内容)

rmdir()如果文件夹包含任何文件,则该函数将失败.我可以循环遍历目录中的所有文件,如下所示:

foreach (scandir($dir) as $item) {
    if ($item == '.' || $item == '..') continue;
    unlink($dir.DIRECTORY_SEPARATOR.$item);
}
rmdir($dir);
Run Code Online (Sandbox Code Playgroud)

有没有办法一次性删除它?

php file-io delete-directory

32
推荐指数
2
解决办法
5万
查看次数