filereader

Java字符输入输出流

我们两清 提交于 2019-12-11 18:07:08
1 package org.java; 2 3 import java.io.BufferedReader; 4 import java.io.BufferedWriter; 5 import java.io.File; 6 import java.io.FileReader; 7 import java.io.FileWriter; 8 import java.util.Scanner; 9 10 11 public class Main16 { 12 public static void main(String[] args) { 13 /* 14 * 利用输入/输出流类,从键盘上读入若干字符, 15 * 然后把字符显示在屏幕上的同时,写到文件test.dat文件中。 16 */ 17 try { 18 String path="C:\\Users\\Nirobert Einteson\\Desktop\\java\\File\\";//文件的所在的目录 19 File fileData=new File(path+"test.dat"); 20 FileWriter fileWriter=new FileWriter(fileData);//字符型 21 BufferedWriter bufferedWriter=new BufferedWriter(fileWriter);

Count the amount of times a string appears in a file

孤人 提交于 2019-12-11 16:32:16
问题 I'm trying to figure out how I would read a file, and then count the amount of times a certain string appears. This is what my file looks like, it's a .txt: Test Test Test Test I want the method to then return how many times it is in the file. Any idea's on how I could go about doing this? I mainly need help with the first part. So if I was searching for the string "Test" I would want it to return 4. Thanks in advanced! Hope I gave enough info! 回答1: Here you are: public int countStringInFile

JavaSE——IO流之字符流

和自甴很熟 提交于 2019-12-11 12:48:52
1. 概述 字符流只能读写文本文件 Reader :字符输入流的父类 InputStreamReader 是字节流通向字符流 的桥梁 Writer :字符输出流的父类 OutputStreamWriter 是字符流通向字节流 的桥梁 字符流出现的原因:由于字节流操作中文不是特别方便,所以java就提供了字符流。 编码: 就是把字符串转换成字节数组 =>字符流 = 字节流 + 编码表 2. OutputStreamWriter 字符流写数据的方式 public void write(int c) 写一个字符 public void write(char[] cbuf) 写一个字符数组 public void write(char[] cbuf,int off,int len) 写一个字符数组的一部分 public void write(String str) 写一个字符串 public void write(String str,int off,int len) 写一个字符串的一部分 案例代码 运行结果 OutputStreamWriter的构造方法 OutputStreamWriter(OutputStream out):根据默认编码(GBK)把字节流的数据转换为字符流 OutputStreamWriter(OutputStream out,String charsetName)

FileReader memory leak

给你一囗甜甜゛ 提交于 2019-12-11 12:09:03
问题 I'm using FileReader to upload image files to a client for data fetching and thumbnails display. what I've noticed is, that on the page process, in task manager, the memory just keeps going higher and higher. and when the process stops, and memory stay high and never goes down. can you please tell me what I am doing wrong here? to check, please upload more then 200 pictures, up to 30MG. and see that the memory keeps on leaking thank you in advanced. -- here is a link to a code example on the

Read a .txt file and return a list of words with their frequency in the file

隐身守侯 提交于 2019-12-11 11:43:16
问题 I have this so far but it only prints the .txt file to the screen: import java.io.*; public class ReadFile { public static void main(String[] args) throws IOException { String Wordlist; int Frequency; File file = new File("file1.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); String line = null; while( (line = br.readLine()) != null) { String [] tokens = line.split("\\s+"); System.out.println(line); } } } Can anyone help me so it prints a word

How to read any local file by chunks using JavaScript?

天涯浪子 提交于 2019-12-11 09:07:07
问题 How can I read any large file(greater than 1 gigabytes) locally by chunks(2kb or more),and then convert the chunk to a string, process the string and then get the next chunk and so on until the end of the file? I'm only able to read small files and convert it to string, as you can see from the code I don't know how to read the file by chunks. The browser freezes if I try it with a file greater than 10mb. <html> <head> <title>Read File</title> </head> <body> <input type="file" id="myFile"> <hr

Edit file - pure js

家住魔仙堡 提交于 2019-12-11 07:36:27
问题 How do I edit a file in pure js (without node)? I get a file with an input field and I read its text like this: var fileReader = new FileReader(); fileReader.readAsText(file); fileReader.onload = function () { alert(this.result); } So, pretty straight forward. I tried to look on the net how to use a fileWriter but with no success. I just need to edit the text inside that file and save it, how can I do? 回答1: You can't write files in a browser, you'll have to use node. 回答2: You can read in the

How to save text file contents to Javascript variable?

末鹿安然 提交于 2019-12-11 06:54:37
问题 I'm trying to read a text file of over 150,000 lines of text. I want to be able to read the text file and pass it as a parameter for processFileContent. I tried it this way, but it doesn't work. Also, is there a better way to do this for such big data? function readFile(file) { var reader = new FileReader(); reader.onload = function (evt) { var data = evt.target.result; }; reader.readAsText(file); return data; } document.getElementById('file').addEventListener('change', readFile, false); var

How to convert a String to actual file that was generated from FileReader.readAsDataURL()

狂风中的少年 提交于 2019-12-11 06:36:28
问题 I have generated a string of a file using this: const reader = new window.FileReader(); reader.readAsDataURL(file); reader.onloadend = () => { var x = reader.result.toString(); console.log("File String :: ", x); }; How to convert this string to actual file like if the previous file was a PDF then this string will converted to a pdf file reader.result.toString() gives me a string like this "data:application/pdf;base64,JVBERi0xLjQKJSDi48/..........." I want to convert it back to pdf FileReader

readAsDataURL corrupted output

别来无恙 提交于 2019-12-11 05:07:22
问题 I have coded a meteor App, sending slices of binary data to a server with the help of the FileReader API. The method processing the slices on the client side: var readSlice = function() { var start, end; start = chunk * chunkSize; if (start > file.size) { start = end + 1; } end = start + (chunkSize - 1) >= file.size ? file.size : start + (chunkSize - 1); fileReader.onload = function(event) { if (++chunk <= chunks) { Meteor .apply("saveChunk", [ event.target.result.split(',')[1], file.name,