标签: fileinputstream

C++线到矢量

哇我今天到处都有问题,如果它们似乎重叠,我道歉,但是每一个问题都会出现另一个问题......因为有一件事情不行......但我应该用别的东西...... ....等等.

无论如何,我有一个文本文件:

6
3.0 2.5 -1.5 0.0 1.7 4.0
6 10
Run Code Online (Sandbox Code Playgroud)

6是第二行中的"浮点数"(3.0,2.5等...)3.0,2.5,-1.5都是一系列浮点数.6和10只是2个整数.

我有一个矢量

std::vector<double> numbers;
Run Code Online (Sandbox Code Playgroud)

我需要做的就是将第二行放入数字中.所以现在我有

ifstream myfile (filename.c_str());
Run Code Online (Sandbox Code Playgroud)

我可以简单地只做一个myfile >>来得到第一个值(6)但是我怎样才能把第二行放在我的向量中?记住我只知道第2行(在这种情况下为6),只知道第2行是多大的.

最后2个数字也不应该在这个向量中,而是两个单独的值.哪个我可以做myfile >> a >> b.

对于很多问题再次抱歉.但我一直在寻找各地,并提出错误的问题.

c++ file vector fileinputstream

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

写入outputstream处理时出现错误

我将在我的学术Java课程中建立一个httpserver,该服务器应仅支持基本的GET和POST请求。

我想知道是否存在一种处理错误的优雅方法,该错误发生在将 html文件流内容(以及我已经发送响应头)写入HttpServer输出流的过程中。

优雅的方式是指显示用户或将用户重定向到“内部服务器错误”错误页面。

我尝试使用501错误代码重新发送http响应标头,但是java抛出一个异常,声称标头已经发送过...

一种解决方法是将文件的内容读取到内存中,然后再发送标头和内容,但是可能会出现其他问题,此外,我不想在将大文件发送出去作为响应之前将其加载到内存中。

java error-handling http fileinputstream

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

如何将通用文件发送到平针织服务并正确接收?

我正在开发一个使用Dropbox API的Jersey服务.

我需要将一个通用文件发布到我的服务中(该服务可以管理各种文件,也可以使用Dropbox API).

客户端

所以,我实现了一个简单的客户端:

  • 打开文件,
  • 创建与URL的连接,
  • 设置正确的HTTP方法,
  • 创建一个FileInputStream并使用字节缓冲区在连接的输出流上写入文件.

这是客户端测试代码.

public class Client {

  public static void main(String args[]) throws IOException, InterruptedException {
    String target = "http://localhost:8080/DCService/REST/professor/upload";
    URL putUrl = new URL(target);
    HttpURLConnection connection = (HttpURLConnection) putUrl.openConnection();

    connection.setDoOutput(true);
    connection.setInstanceFollowRedirects(false);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("content-Type", "application/pdf");

    OutputStream os = connection.getOutputStream();

    InputStream is = new FileInputStream("welcome.pdf");
    byte buf[] = new byte[1024];
    int len;
    int lung = 0;
    while ((len = is.read(buf)) > 0) {
      System.out.print(len);
      lung += len;
      is.read(buf);
      os.write(buf, 0, len); …
Run Code Online (Sandbox Code Playgroud)

java rest jersey fileinputstream

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

在java中复制文件

你能告诉我为什么这个字符" ÿ "出现在我的输出文件的末尾.(我用try/catch)

        File f1 = new File("C:/Users/NetBeansProjects/QuestionOne/input.txt");
        File f2 = new File("C:/Users/NetBeansProjects/QuestionOne/output.txt");
        fin = new FileInputStream(f1);
        fout = new FileOutputStream(f2);

        do {
            i = fin.read();
            fout.write(i);

        } while (i != -1);
Run Code Online (Sandbox Code Playgroud)

代码复制文件内容,但它以这个奇怪的字符结束.我是否必须包含整个代码?

谢谢.

java inputstream file fileinputstream

4
推荐指数
3
解决办法
334
查看次数

如何使用字节数组作为参数构建FileInputStream对象

我有一个zip文件,解码后我得到一个字节数组现在我想用byte []对象创建一个FileInputStream对象.我不想创建文件而是传递数据内容做FileInputStream.有什么办法吗?

以下是代码:

byte[] decodedHeaderFileZip = decodeHeaderZipFile(headerExportFile);
FileInputStream fileInputStream = new FileInputStream(decodedHeaderZipFileString);
Run Code Online (Sandbox Code Playgroud)

编辑:我想用FileInputStream构建一个ZipInputStream对象.

java performance bytearray fileinputstream java-ee

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

在android中读取二进制文件

我创建了一个类型的自定义对象,Task我想将其保存在内部存储中的二进制文件中.这是我创建的类:

public class Task {

    private String title;
    private int year;
    private int month;
    private int day;
    private int hour;
    private int minute;

    public Task(String inputTitle, int inputYear, int inputMonth, int inputDay, int inputHour, int inputMinute) {

        this.title = inputTitle;
        this.year = inputYear;
        this.month = inputMonth;
        this.day = inputDay;
        this.hour = inputHour;
        this.minute = inputMinute;

    }

    public String getTitle() {

        return this.title;

    }

    public int getYear() {

        return this.year;

    }

    public int getMonth() {

        return this.month;

    }

    public …
Run Code Online (Sandbox Code Playgroud)

java android fileinputstream fileoutputstream

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

如何在 Java 中将 blob 格式的图像保存到 MySQL

为了完成一项任务,我必须将图像以 blob 格式存储到 MySQL 中(即使将图像路径存储在数据库中并将图像保存在 localcopy 的文件夹中会更好也更理想)。

到目前为止,我已经研究过并找不到任何可以帮助我的答案,这就是我迄今为止所做的

单击按钮后,将立即触发:

empdao.insertImage(fis);
Run Code Online (Sandbox Code Playgroud)

图像填充在另一个偶数侦听器上,如下所示:

static FileInputStream fis = null;
static String path = null;
path = filechooser.getSelectedFile().getAbsolutePath();
File image = new File(path);
fis = new FileInputStream (image);
Run Code Online (Sandbox Code Playgroud)

下面的代码负责将其添加到数据库中。

public void insertImage(FileInputStream fis) throws SQLException {



Connection c = getConnection();     

    String query = "INSERT INTO Picture (picture) VALUES (?)";

    System.out.println(query);

    PreparedStatement pstmt = c.prepareStatement(query);

    pstmt.setBinaryStream(1, fis);

    pstmt.executeUpdate();

    c.close();
}
Run Code Online (Sandbox Code Playgroud)

然而,问题是我需要它来将它转换为 blob,但我不知道如何转换,有人可以帮助我或指导我如何将所选图像作为 blob 字段存储到 MySQL 中。

目前,当它将它添加到数据库中时,我在图片列下输入了 java.io 文件。

java mysql jdbc fileinputstream

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

将剪贴板粘贴到闪亮的应用程序中?

这是一个示例,我可以浏览文件作为输入,但我不想浏览,而是想粘贴剪贴板中的数据。任何想法 ?

if (interactive()) {
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv")
),
tags$hr(),
checkboxInput("header", "Header", TRUE)
),
mainPanel(
tableOutput("contents")
)
)
)

server <- function(input, output) {
output$contents <- renderTable({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
read.csv(inFile$datapath, header = input$header)
})

}
shinyApp(ui, server)
}
Run Code Online (Sandbox Code Playgroud)

clipboard r input fileinputstream shiny

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

打开一个12kb的文本文件需要花费太长时间......?

以下代码可以正常工作,但需要花费太长时间(超过一分钟)才能打开一个小文件.LogCat显示了很多"## ms"中"GC_FOR_MALLOC释放#### objects/######字节"的实例.有什么建议?

 File dirPath = new File(Environment.getExternalStorageDirectory(), "MyFolder");
 String content = getFile("test.txt");

 public String getFile(String file){
  String content = "";
  try {
   File dirPathFile = new File(dirPath, file);
   FileInputStream fis = new FileInputStream(dirPathFile);
   int c;
   while((c = fis.read()) != -1) {
    content += (char)c;
   }
   fis.close();
  } catch (Exception e) {
   getLog("Error (" + e.toString() + ") with: " + file);
  }
  return content;
 }
Run Code Online (Sandbox Code Playgroud)

更新:

这就是现在的样子:

File dirPath = new File(Environment.getExternalStorageDirectory(), "MyFolder");
String content = getFile("test.txt");

public String …
Run Code Online (Sandbox Code Playgroud)

android sd-card fileinputstream

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

无法在文件中找到换行符(java)

我试图获取文件的最后一行,但我的输出显示它从未找到它.我也尝试寻找所有行开头的"[",但除非跳转完美,否则程序不会跳过"[".我试图寻找 "\ r \n",System.getProperty( "line.separator"),\ r和\n.最可能是它的一个愚蠢的错误,但如果我拥有它而我找不到它,那么其他人也可能遇到它.

        RandomAccessFile raf = new RandomAccessFile(fileLocation, "r");
        //Finds the end of the file, and takes a little more
        long lastSegment = raf.length() - 5;
        //**Looks for the new line character \n?**
        //if it cant find it then take 5 more and look again.
        while(stringBuffer.lastIndexOf("\n") == -1)  {
            lastSegment = lastSegment-5;
            raf.seek(lastSegment);
            //Not sure this is the best way to do it
            String seen = raf.readLine();
            stringBuffer.append(seen);
        }
        //Trying to debug it and understand
        int location …
Run Code Online (Sandbox Code Playgroud)

java file-io newline random-access fileinputstream

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