filereader

java中获取路径的几种方式

为君一笑 提交于 2020-01-08 09:29:29
总是忘记, 备份一下,方便下次用. 第一种: File directory = new File("");//参数为空 String courseFile = directory.getCanonicalPath() ;System.out.println(courseFile); 结果:C:\Documents and Settings\Administrator\workspace\projectName获取当前类的所在工程路径; 第二种: File f = new File(this.getClass().getResource("/").getPath()); System.out.println(f); 结果:C:\Documents and Settings\Administrator\workspace\projectName\bin 如果不加“/” File f = new File(this.getClass().getResource("").getPath()); System.out.println(f); 结果:C:\Documents and Settings\Administrator\workspace\projectName\bin\com\test 第三种:URL xmlpath = this.getClass().getClassLoader(

Best way to read data and store from file?

限于喜欢 提交于 2020-01-06 15:50:55
问题 I have a text file which stores data in this manner: Player name: NAME HERE Speed: 7 Strength: 9 Stamina: 4 Player name: ANOTHER NAME HERE Speed: 5 Strength: 8 Stamina: 3 The same file contains about fifteen different players, and I want to gather values from each of them, store in a temporary race variable, then calculate the mean value of the speed strength and stamina and present a winner. My first idea was to use regular expression but I am currently investigating if there are another,

缓冲流的基本用法

时间秒杀一切 提交于 2020-01-06 14:56:32
package myIO; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; /* * BufferedWriter:将文本写入字符输出流,缓冲各个字符,从而提供单个字符、数组和字符串的写入 * BufferedReader:从字符输入流中读取文本,缓冲各个字符,从而实现字符、数组和行的高效读取 */ public class BufferdStreamDemo { public static void main(String[] args) throws IOException { //创建输出缓冲流对象 BufferedWriter bw = new BufferedWriter(new FileWriter("bw.txt")); //方法 bw.write("jiangziyu"); bw.flush(); //释放资源 bw.close(); //创建输入流缓冲对象 BufferedReader br = new BufferedReader(new FileReader("bw.txt")); // //一次读写一个字符 // int

Why is FileReader.readAsText() returning null?

时光怂恿深爱的人放手 提交于 2020-01-06 12:42:32
问题 I am trying to read a file in the same directory of an HTML and JavaScript file however it seems to be returning null. Below I have added the code I have from each file. HTML File: <html> <!-- Code to call the Google Maps API and link style.css sheet --> <body> <div class="content"> <div id="googleMap"></div> <div id="right_pane_results">hi</div> <div id="bottom_pane_options"> <button onclick="get_parameters()">Try It</button> </div> </div> </body> <script type="text/javascript" src=".

javascript sendfile binary data to web service

五迷三道 提交于 2020-01-06 07:28:16
问题 At work we are trying to upload files from a web page to a web service using html 5/javascript in the browser end and C# in the web service. But have some trouble with encoding of some sort. As for the javascript we get the file's binary data with help from a FileReader. var file = ... // gets the file from an input var fileReader = new FileReader(); fileReader.onload = dataRecieved; fileReader.readAsBinaryString(file); function dataRecieved() { // Here we do a normal jquery ajax post with

reading a textfile from r.raw on android

纵饮孤独 提交于 2020-01-05 07:25:11
问题 I've got a json file in R.raw.test123, I need to process that with GSON. Step one is; read the text into a string, I want to do that using; BufferedReader r = new BufferedReader(new FileReader(file)); The FileReader expects a string as filename, but how do I turn R.raw.test123 into a string which I can pass to the FileReader. I've googled for about 4 hours on this, still can't find it. And I know its probally a noob question, but I'm new to droid programming, I come from a .net background, so

JavaScript - Reading URLs from a file and saving them as elements in an array

牧云@^-^@ 提交于 2020-01-04 07:28:06
问题 I have very little javascript skills and I would like to pass lines of a file as String arguments to a pre-written function. Basically what I want to do is read a file in this type of format, with each url on its own line: www.url1.com www.url2.com ...And so on How can I read a local file and save each line to a String array? Thank you very much, and let me know if anything is unclear 回答1: You can do this by looking at FileList, File, and FileReader web APIs. Note that your browser may not

how to assign value of readAsDataURL() to a variable?

痴心易碎 提交于 2020-01-04 06:04:23
问题 okay so I've seen many examples and questions on using readAsDataURL(), but none of them seem to resolve my issue. Following is my code : $(document).ready(function(){ var fileReader = new FileReader(); $("form").submit(function(e){ e.preventDefault(); console.log(fileReader.readAsDataURL(document.getElementById("userfile").files[0])); }); }); what i get in console is undefined . I'm trying to get the base64 encoded file data on a variable so that i can upload it using ajax. Can anyone tell

how to assign value of readAsDataURL() to a variable?

会有一股神秘感。 提交于 2020-01-04 06:04:12
问题 okay so I've seen many examples and questions on using readAsDataURL(), but none of them seem to resolve my issue. Following is my code : $(document).ready(function(){ var fileReader = new FileReader(); $("form").submit(function(e){ e.preventDefault(); console.log(fileReader.readAsDataURL(document.getElementById("userfile").files[0])); }); }); what i get in console is undefined . I'm trying to get the base64 encoded file data on a variable so that i can upload it using ajax. Can anyone tell

Scaling image from input[type=file]

你说的曾经没有我的故事 提交于 2020-01-02 23:03:03
问题 Desired Result: I'm looking to select an image from a file upload form, scale it to a thumbnail and display it. Problem: The following code does exactly what I want it to, however, I must select the file not once, but twice to see the image preview. (Select image, no display, select same image, I get the scaled display) Everything was working great when I was manually assigning width & height, though now that i'm scaling it - this issue began. I'm in need of a code review! When I comment out