标签: readfile

在jar/war文件中读取maven.properties文件

有没有办法maven.properties用Java 读取jar/war文件中的文件()的内容?我需要从磁盘读取文件,当它没有被使用时(在内存中).有关如何做到这一点的任何建议?

此致,Johan-Kees

java maven readfile

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

Java文本输入:如何忽略以某些字符开头的行?

我基本上想要忽略某些带有字符的行,比如是否有一行

// hello, i'm bill
Run Code Online (Sandbox Code Playgroud)

我想在阅读时忽略该行,因为它包含字符"//".我怎样才能做到这一点?我尝试了方法skip(),但它给了我错误.

public String[] OpenFile() throws IOException {

  FileReader reader = new FileReader(path);
  BufferedReader textReader = new BufferedReader(reader);

  int numberOfLines = readLines();
  String[] textData = new String[numberOfLines];
  int i;

  for (i=0; i<numberOfLines; i++) {
      textData[i] = textReader.readLine();
  }

  // close the line-by-line reader and return the data
  textReader.close();
  return textData;
}

int readLines() throws IOException {
  FileReader reader = new FileReader(path);
  BufferedReader textReader = new BufferedReader(reader);
  String line;
  int numberOfLines = 0;

  while ((line = textReader.readLine()) …
Run Code Online (Sandbox Code Playgroud)

java lines textreader readfile

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

读取文件后生成事件

我想在完成文件读取之后在Java中引发一些事件,以便处理程序可以捕获事件并继续执行下一个任务.我无法在完成文件读取后找到Java中存在的事件.

是他们的任何方式,或任何其他替代方案.

java file-handling readfile r.java-file

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

PHP Readfile()不适合我,我不知道为什么

我试图让这个代码工作,但由于某种原因,所有的回声都能够输出正确的内容,但标题似乎不想强制下载我的文档.以下是我试图为文件下载构建的文件.它被设置为输入如下代码:根据用户权限downloader.php?f=13&t=doc下载已命名的文件201-xxx.doc201-xxx.pdf从两个文件夹中的一个文件夹下载.

所有逻辑都适用于底部的标题信息.如果我注释掉标题内容类型和标题内容处置,那么它会将文件读入浏览器.如果包含这些行中的任何一行,它会给出一个错误"Error 6 (net::ERR_FILE_NOT_FOUND): The file or directory could not be found."

<?php
//ob_start();
if ( !defined('__DIR__') ) define('__DIR__', dirname(__FILE__));
define( "TLOJ_FSROOT", __DIR__ . "/" );
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');

$lessonnumber = $_REQUEST['f'];
$type = $_REQUEST['t'];

    if ( $lessonnumber < '10' ) { $threedigitlesson = '00' . $lessonnumber; }
    elseif ( $lessonnumber < '100' ) { $threedigitlesson = '0' . $lessonnumber; }
    else { $threedigitlesson = $lessonnumber; }
    $filenamestart = "201-" . $threedigitlesson;

    $contenttype …
Run Code Online (Sandbox Code Playgroud)

php download readfile

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

在哪里保存文本文件才能将其读入Android项目

我已经四处寻找保存一般文本文件的位置以便阅读我的Android项目,但找不到明确的答案.当我将"foo.txt"文件保存到我的res/raw文件夹中时,有人建议(我必须创建原始文件夹),R.java文件会出现以下错误:

public static final class raw {
    public static final int 1_1=0x7f050000;
}
Run Code Online (Sandbox Code Playgroud)

这是因为我的文件在第一行包含字符串"1_1",我想要它.文件夹结构中的哪个位置我应该把我的文件读出来?该文件不是由Android创建的,而是由我手动创建的.

有人也请告知如何以下列格式阅读文件?我希望能够逐个读取字符串和数字,并在我的Android项目中插入java变量.最好用逗号或空格分隔?

1_1
String
Int
Int String String Int Int Float Float Int Int
Int String String Int Int Float Float Int Int
Int String String Int Int Float Float Int Int
Int String String Int Int Float Float Int Int
Int String String Int Int Float Float Int Int
Int String String Int Int Float Float Int Int
Run Code Online (Sandbox Code Playgroud)

更新了更多代码:

package com.my.package;

import java.io.File;

import android.app.Activity;
import …
Run Code Online (Sandbox Code Playgroud)

java android readfile

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

java.util.NoSuchElementException错误

我尝试从文本文件中读取整行,并以不同的方式显示它们.例如,

    123456J;Gabriel;12/12/1994;67;67;89;
Run Code Online (Sandbox Code Playgroud)

但控制台的结果如下:

    123456J Gabriel 72(which is average of three numbers)
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

    public class Student{

String adminNo;
String name;
GregorianCalendar birthDate;
int test1,test2,test3;

public Student(String adminNo,String name,String birthDate,int test1, int test2, int test3){
    this.adminNo = adminNo;
    this.name = name;
    this.birthDate = MyCalendar.convertDate(birthDate);
    this.test1 = test1;
    this.test2 = test2;
    this.test3 = test3;
}

public Student(String studentRecord){
    String strBirthDate;
    Scanner sc = new Scanner(studentRecord);
    sc.useDelimiter(";");
    adminNo = sc.next();
    name = sc.next();
    strBirthDate = sc.next();
    birthDate = MyCalendar.convertDate(strBirthDate.toString());
    test1 = sc.nextInt();
    test2 = …
Run Code Online (Sandbox Code Playgroud)

java readfile

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

在Windows Phone 8中读取文件:值不在预期范围内

打开存储在项目中的文件时,我确实遇到了问题.我需要打开一些文件(pdf,html,...)并且遇到同样的问题:值不在预期范围内.

我尝试了几种方法:

一个)

private async Task<string> ReadFileContentsAsync(string fileName)
{
    StorageFolder foldera = ApplicationData.Current.LocalFolder;

    try
    {
        Stream filea = await foldera.OpenStreamForReadAsync("/Assets/Data/htm/" + fileName + ".htm");


        ...
    }
    catch (Exception e)
    {
        Debug.WriteLine("ERROR ReadFileContentsAsync " + e.Message);
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

b)

private async Task<string> ReadFileContentsAsync(string fileName)
{
    try
    {
        StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(
                new Uri("ms-appdata:///Assets/Data/htm/" + fileName + ".htm", UriKind.RelativeOrAbsolute));

        ...
    }
    catch (Exception e)
    {
        Debug.WriteLine("ERROR ReadFileContentsAsync " + e.Message);
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

C)

StorageFile file2 …
Run Code Online (Sandbox Code Playgroud)

c# readfile windows-phone-8

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

读取由空格分隔的未知数量的整数到每行一个向量

我文件的每一行都包含一个未知数量的整数,这些整数用空格分隔.我想在每一行中读取这些整数的向量.

以下是此类文件的示例:

11 3 0 1
4 5 0 3
2 3 4 1
23 4 25 15 11
0 2 6 7 10
5 6 2
1
11
Run Code Online (Sandbox Code Playgroud)

我已经能够使用以下方法成功读取少量数据(请注意,outer_layers是包含我试图填充的这些向量的向量):

for (int i = 0; i < outer_layers.size(); i++)
{
    while (in >> temp_num)
    {
        outer_layers[i].inner_layer.push_back(temp_num);
        if (in.peek() == '\n')
            break;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试读取大量数据时,有时它会在一个向量下读取两行.在其中一个文件中,在24行中,它有两次读取两行,因此最后两个向量没有任何数据.

我无法绕过它.我有什么想法我做错了吗?

编辑:我在麻烦制造者文件的一些行中注意到的一些有趣的事情是这样的:

比方说有三行.

23 42 1 5
1 0 5 10
2 3 11
Run Code Online (Sandbox Code Playgroud)

第1行读入就好了23 42 1 5; 然而,第2行和第3行一起读取1 0 5 10 …

c++ vector readfile

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

如何在Erlang中读取文件中的数据结构?

我正在进行一项练习,要求我在测试我的应用程序时不断重用Erlang中的数据结构,并且有点费力.保存它们很容易

file:write_file(Path, Data). 
Run Code Online (Sandbox Code Playgroud)

然而,我正在努力阅读数据,read_file和read_lines似乎使事情变得不必要地复杂,而不是因为缺乏搜索,我还没有找到一个好的方法来准备结构回Erlang,虽然我已经看到了一些广泛的CSV和XML解析器.我觉得必须有一个简单的方法,但我不知道术语.到目前为止,我有:

parse(Filename) ->
  {ok, Data} = file:read_file(Filename),
  binary:split(Data, [<<"\n">>], [global]).
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏.

io erlang readfile data-structures

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

如何在不使用stdio.h库的情况下从文件读写?

背景:这是关于考试学习指南的问题.

问题:编写一段代码,该代码使用执行以下操作的低级Unix I/O系统调用(不是stdio或iostream):

o打开名为"data.txt"的文件进行读取.

o从文件中读取最多512个字节到名为buf的数组中.

o关闭文件.

如果在任何步骤中出现错误,请打印错误消息并退出程序.包括代码使用的任何变量的定义.

我在该c语言的linux环境中使用pico IDE .我知道如何轻松地使用它,#include <stdio.h>但我不知道如果没有它我将如何编写代码.现在我现在有:

#include <stdio.h>

int main()
{
 // File var
 FILE *fileVar;
 char buff[512];

 // Open it
 fileVar = fopen("data.txt", "r");

 // Check for error
 if(fileVar == NULL)
 {
   perror("Error is: ");
 }
 else
 {
   fscanf(fileVar, "%s", buff);
   printf("The file contains:  %s\n", buff);
   fgets(buff, 512, (FILE*)fileVar);
   fclose(fileVar);
 }

}
Run Code Online (Sandbox Code Playgroud)

如何在不使用库的情况下将上述代码翻译成工作#include<stdio.h>

c readfile

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