readfile

重新认识Java-I/O流

半世苍凉 提交于 2019-11-29 13:42:09
  记录一下在工作中遇到的一些有意思的问题,在之前系统学习过Java的IO流,但是在工作中长时间没有用到导致在这几天的一个需求中抓瞎了,查了好一会的资料耽误了一段时间,好了废话不多说,下面简单讲一下需求。   需求是这样的,数据库中有一张数据表的一个BLOB字段中存放了一个excel文件,我需要将这个文件放到服务器指定的文件夹下面。思路是这样的:1、在指定文件夹下面创建excel文件。2、jdbc取出数据库中的文件。3、各自转换为输入输出流将数据库中的文件数据导入到指定文件内。下面是代码:    package helloTest; import com.fr.base.FRContext; import com.fr.data.AbstractTableData; import com.fr.general.data.TableDataException; import com.fr.third.org.apache.poi.hssf.usermodel.HSSFSheet; import com.fr.third.org.apache.poi.hssf.usermodel.HSSFWorkbook; import java.io.*; import java.sql.Connection; import java.sql.DriverManager; import java

Read and split a text file (java)

99封情书 提交于 2019-11-29 13:06:22
I have some text files with time information, like: 46321882696937;46322241663603;358966666 46325844895266;46326074026933;229131667 46417974251902;46418206896898;232644996 46422760835237;46423223321897;462486660 For now, I need the third column of the file, to calculate the average. How can I do this? I need to get every text lines, and then get the last column? You can read the file line by line using a BufferedReader or a Scanner , or even some other techinique. Using a Scanner is pretty straightforward, like this: public void read(File file) throws IOException{ Scanner scanner = new Scanner

Broken image with readfile and file_get_contents

杀马特。学长 韩版系。学妹 提交于 2019-11-29 10:52:26
I'm trying to use a function in order to get this working: <img src='login.php?image=ind_legend.jpg'> But I can't pass through the function to place the image. I went back a couple of steps and tried only this part of the code: <?php $file = "http://localhost/sales/test.jpg"; header('Content-type: image/jpeg'); readfile($file); ?> or using this function: echo file_get_contents($source); but the fact is that the only thing I get is a broken image cross (IE) or nothing in Firefox. I would appreciate any suggestions Thanks in advance You certainly have some whitespace in your PHP script, or a UTF

PHP readfile() of external URL

空扰寡人 提交于 2019-11-29 10:06:17
Can I use external URLs in readfile()? header('Content-type: application/pdf'); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: inline; filename="'.$file.'" '); //header('Content-Length: ' . filesize("http:...z/pub/".$file.'.pdf')); @readfile("http://...z/pub/".$file.'.pdf'); The PHP manual on readfile states: A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers

readFileSync is not a function

流过昼夜 提交于 2019-11-29 05:44:27
问题 I am relatively new to Node.js and have been looking around but cannot find a solution. I did check the require javascript file and it does not seem to have a method for "readFileSync". Perhaps I don't have a proper require file? I had a hard time finding this file, everywhere talked about it but most people did not post where to get it. I installed Node.js and have the require.js file. My current code is like this: fs = require(['require'], function (foo) { //foo is now loaded. }); console

CLion C++ can't read/open .txt file in project directory

岁酱吖の 提交于 2019-11-29 04:02:30
I have a .txt file in my project directory that I made and populated with data. directory structure looks like: /Users/asd/ClionProjects/ProjectWithTemplates/ main.cpp cmake twoday.txt here is my code: #include <iostream> #include <array> #include <cmath> #include <fstream> using namespace std; /* print array prototype */ template <size_t N> void printArray(const array<double , N> & arr); /* mean function prototype */ template <size_t N> double meanArray(const array<double , N> & arr); /* standard deviation prototype */ template <size_t N> double sDeviation(const array<double , N> & arr); int

read file from external storage

感情迁移 提交于 2019-11-29 02:04:36
I simply cannot find how to get one specified file from the external storage. I know that with getExternalStoragePublicDirectory(), you get the external storage directory but I can't get further. I need some kind of method where you have to give the name of the file and it returns the file. Thanx Better than using File.separator is this, which is standard Java: final File file = new File(Environment.getExternalStorageDirectory() .getAbsolutePath(), filename); You can just do this: File f = new File(Environment.getExternalStorageDirectory() .getAbsolutePath() + File.separator + fileName);

Asynchronously reading and caching multiple files in nodejs

三世轮回 提交于 2019-11-28 22:08:20
I have an array which keeps URL of several files. For example: var files = ['1.html', '2.html', '3.html']; I need to read them asynchronously and save them in an object named cache (cache = {}). To do this I used the code: for(var i = 0; i < files.length; i++){ require('fs').readFile(files[i], 'utf8', function (error,data) { cache[files[i]]=data; }); } In the end I have the result: cache = { undefined : 'File 3 content' } I do understand that the "readFile" acts after the loop is ended and it looses it's scope. Is there a way to fix this or another method to read files from an array and cache

ReadFile in Base64 Nodejs

本秂侑毒 提交于 2019-11-28 19:37:37
问题 I'm trying to read an image from client side encoded in base64. How to read with nodejs? My code: // add to buffer base64 image var encondedImage = new Buffer(image.name, 'base64'); fs.readFile(encondedImage, "base64", function(err, buffer){ if ( err ) { console.log('In read file') console.log(err) } else { // check err lwip.open(buffer, 'jpg', function(err, image){ console.log('in open') if ( err ) console.log(err) if ( image ) console.log(image) // check 'err'. use 'image'. // image.resize(

node.js的async和await

风格不统一 提交于 2019-11-28 15:42:54
一、async和await是什么 ES2017 标准引入了 async 函数,使得异步操作变得更加方便,async其实本质是Generator函数的语法糖 async表示函数里有异步操作 await表示在后面的表达式需要等待结果 二、node异步编程的演进的四个阶段 我们来回顾一下异步编程的写法的演进过程 第一阶段 通过回调函数 fs.readFile('/etc/passwd', 'utf-8', function (err, data) { if (err) throw err; console.log(data); }) 这样的方式会造成嵌套过多,在调用过多的时候,就变成了下面这样的写法,传说中的callback hell fs.readFile(fileA, 'utf-8', function (err, data) { fs.readFile(fileB, 'utf-8', function (err, data) { fs.readFile(fileC, 'utf-8', function (err, data) { // ... }); }); }); 2. 第二阶段 通过Promise Promise 对象允许将回调函数的嵌套,改成链式调用。 采用 Promise,连续读取多个文件,写法如下。 const readFile = function (fileName)