bufferedreader

Write to JSONObject to JSONfile

浪尽此生 提交于 2019-12-11 16:13:56
问题 I have an app that has to take a string, encode it into JSONObject format and write it into a JSON file in the SD. It all seems to be working fine apart from writing part. I have <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> command in my MANIFEST and that's my code btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // String lines[] = importantemail.split("\\r?\\n"); // String firstLine = (lines[0]); //String secondLine

Convert BufferedReader to InputStream

我们两清 提交于 2019-12-11 14:14:02
问题 I have an API with a useful method that requires an InputStream argument. The data that I want to provide to this method is currently represented by a BufferedReader. The library is prepared to deal with byte streams, I have character data that I'm going to feed it. I am not changing between different encodings. I have spent what seems an inordinate amount of time trying to discover what I was sure would be a standard way to do this, but there doesn't seem to be one. I do NOT want to read all

FileNotFoundException problem

元气小坏坏 提交于 2019-12-11 10:59:46
问题 I've just finished reading 'Java for Dummies' and have begun to create a simple POS program. I have been having trouble getting the program to do what I want it to do! I have two actionListeners linked to each of the following buttons, 'Amigos' and 'Fosters'. I also have two text fields, one showing the price of the individual drink and then other used for a sub-total. I did have the sub-total working to add up multiples of the same drink, but not an 'Amigos' with a 'Fosters'. This was

Java BufferedReader while loop out of bounds exception

吃可爱长大的小学妹 提交于 2019-12-11 10:48:38
问题 I am using BufferedReader to read data from a text file. The variable "reg" is the fourth entry in the string of data that I am trying to access. I am getting the exception: "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3" Here is my code: package calctest; import static calctest.CalcTest.reg; import java.io.*; public class CalcTest { static Integer reg, prov; public static void main(String[] args) throws Exception{ String readFile = "M:\\MandNDrives\\mwallace\\JAVA

loading csv into mysql table

限于喜欢 提交于 2019-12-11 10:08:05
问题 I am faced with a problem with my java-csv-mysql gui application that i am working on. i will breakdown the application in the following functions: 1. select a CSv using a JFileChooser, 2. reading the csv 3. importing the csv to Mysql table 4. displaying the csv contents once they are imported into the Table. I have managed to get it to do the following functions. 1. select a csv file 2. read through the csv file...-reads only one row 3. display read records I have problems when it come to

BufferReader.skip () performance

只谈情不闲聊 提交于 2019-12-11 07:55:33
问题 I can see vast difference in performance between below two programs. import java.io.*; import java.util.Date; class SkipProg2 { public static void main (String args[]) { System.out.println (" File Reading "+ args.length); System.out.println (" 1st Arg "+ args[0]); System.out.println (" 2nd Arg "+ args[1]); try { FileInputStream fis = new FileInputStream(args[0]); System.err.println("Time before skip : " + new Date()); Long off = Long.parseLong(args[1]); fis.skip (off); System.err.println(

Open a BufferedReader in UTF-8

瘦欲@ 提交于 2019-12-11 06:19:20
问题 I have a csv file with characters like Cité , but after make the insert into the DB, I see this Cit¿ I open the file as a BufferedReader , but I don't know how to do it in UTF-8 BufferedReader br = new BufferedReader(new FileReader(csvFile)); 回答1: You could explictly use a FileInputStream and an InputStreamReader using StandardCharsets.UTF_8 , but it's probably simpler to use Files.newBufferedReader: Path path = Paths.get(csvFile); try (BufferedReader reader = Files.newBufferedReader(path)) {

Java BufferedReader read line by customized delimiter [duplicate]

可紊 提交于 2019-12-11 05:48:44
问题 This question already has answers here : How to handle file with different line separator in java? (4 answers) Closed 2 years ago . BufferedReader 's readline() reads a line defined by '\n', is it possible to read a line defined by other delimiter, e.g. ^B ? Thanks 回答1: You can't do it with BufferedReader , however, you can use Scanner and call useDelimiter() method, e.g.: Scanner scanner = new Scanner(new FileInputStream("<file>")); scanner.useDelimiter("\b"); Here's the javadoc. 来源: https:/

Eclipse Console Output Limit

社会主义新天地 提交于 2019-12-11 05:41:21
问题 I am using BufferReader to read log files from a game server. It does work but it just doesn't read the entire file just a small portion of it. My code: public ArrayList<String> readFile(File file){ try (BufferedReader br = new BufferedReader(new FileReader(file.getAbsolutePath()))) { String sCurrentLine; ArrayList<String> list = new ArrayList<String>(); while ((sCurrentLine = br.readLine()) != null) { list.add(sCurrentLine); } return list; } catch (IOException e) { e.printStackTrace(); }

Selecting a file in another directory for a bufferedReader

浪子不回头ぞ 提交于 2019-12-11 05:19:45
问题 I have an initialization file (initialize.java) that pulls in data from fileInput.txt using a fileInputStream, but both of them are in different directories. Project/library/initialize.java Project/resources/text/fileInput.txt my code in initialize.java is: FileInputStream fstream = new FileInputStream("/resources/text/fileInput.txt"); But the file cannot be read. I've also tried FileInputStream fstream = new FileInputStream("./resources/text/fileInput.txt"); But that didn't work too. How can