I have two programs that talk to each other over a TCP connection. When I write the data "STX+1234" where STX is the Ascii character STX or Ctrl B and I expect the written String length to be 6 which it is. On the other side of the socket I create the ServerSocket and use the client socket's InputStream to create a BufferedReader. When I receive the string it now has 12 characters where each original character has been replaced by NUL and the character. How do I read the string as it is originally specified without the conversion? And is the problem on the reader side or the writer side?
I have a problem with this ascii animation program I am working on. I declared a method inside of my class AsciiAnimation extends JFrame implements ActionListener, called
package AsciiAnimation; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; import javax.swing.*; public class AsciiAnimation extends JFrame implements ActionListener{ int currentFrame = 0; ArrayList<String> frameList = new ArrayList<String>();
[Code] ....
Basically I just am trying to figure out how java works with me accessing those 2 data members, currentFrame and frameList inside of my first class ALL in the same package.
I'm unable to get the output for "AverageDriver" to print correctly(5 scores in descending order and average). The output displays the scores the same way they are entered and the average is always zero. The output for the Average program works fine and with the correct output.
import java.util.Scanner; //This class keeps 5 scores entered by the user public class Average { private int[] data; private double mean; public Average()
I am creating a program where it reads the data inside a file and then places this data into arrays. The file I created has numbers 1-30 in it, file named, testing1.txt .
Ok so I know how to import a csv using java. What I'm curious about doing is importing a csv using file chooser, reading the data, sorting the data out by certain parameters, and then outputting a count of each parameter I chose. Say for example I have columns 1,2 and 3. Column 1 has the name, column 2 has the percentage, column 3 has an o'clock time. I want to use queries to sort through the parameters and have a count of each parameter I choose...
I can read the data to a monitor perfectly. But, I'm having problem reading data from an external file into an array of class objects. Here's my attempt at writing the method:
private void openFile() //This method asks the user to enter a file name(including the file extension) and then //Sets the data to an array of Product type { String fileName, storeName="", emptyLine1="", emptyLine2="", name="", productName=""; int demandRate=0; double setupCost=0.0, unitCost=0.0, inventoryCost=0, sellingPrice=0; Scanner inputStream = null;
A method in Java returns a schema. In .net, we use DataTable to get the data from the schema. How to write the following code in Java:
/* Result r = method(); r.DataSchema; */ using (DataTable tbl = new DataTable()) { using (MemoryStream ms = new MemoryStream()) using (StreamWriter sr = new StreamWriter(ms))
I am reading Excel data using java apache. I got format issue while reading double value such as 869.87929 (in excel) into 869.8792899999999 (in java).
if(type.equals("Double")){ String str = content[i-1]; //System.out.println(str); BigDecimal d = new BigDecimal(str); listObjects.add(d); }
Note: type from schema.csv & content [] value from file.xls If I print **str**, it shows value as 869.8792899999999. But i need to get **str** value as 869.87929. How can I get it?
I have to read data from a text file and print it in a new text file. An example of one line is like this: Johnson 85 98 75 89 82
I then have to take the average of all the numbers and assign a "grade" to the numbers for each line of the text file and make a new file so it looks like this for 10 lines:
Name 1 2 3 4 5 Average Grade
Johnson 85 98 75 89 82 85.80 B
My problem is extracting the data from the file so I can use it.
The problem is that I often receive ArrayOutOfBound errors when I try to parse the byte array. I think that I'm reading from the socket in a wrong way..
I'm a complete beginner in Java programming and I'm interested to learn more about its concepts.
Recently, I've been given an exercise which instructs me to display two versions of a picture. The picture to be displayed is provided in the form of a data file of 40,000 digits that are arranged in rows (although there is no marker between rows) and it starts from the top of the picture. So the first digit represents the top left corner of the picture and the last is the bottom right.
Basically, what the exercise wants me to construct a program that plots a dot in one of two colours for each digit. If the digit is in the range 0 to 3 the output should be one colour and for digits in the range 4 to 9 the dot should be in the other colour.
I understand I have to use arrays and also loops to perform this. I'm familiar with the fillEllipse, drawEllipse, drawRectangle and fillRectangle but this exercise is nothing I've attempted before.
We have an autosys job running in our production on daily basis. It calls a shell script which in turn calls a java servlet. This servlet reads these files and inserts the data into two different tables and then does some processing. Java version is 1.6 & application server is WAS7 and database is oracel-11g.
We get several issues with this process like it takes time, goes out of memory etc etc. Below are the details of the way we have coded this process.
1. When we read the file using BufferedReader, do we really get a lot of strings created in the memory as returned by readLine() method of BufferedReader? These files contain 4-5Lacs of line. All the records are separated by newline character. Is there a better way to read files in java to achieve efficiency? I couldnt find any provided the fact that all the record lines in the file are of variable length.
2. When we insert the data then we are doing a batch process with statement/prepared statement. We are making one batch containing all the records of the file. Does it really matter to break the batch size to have better performance?
3. If the tables has no indexes defined nor any other constraints and all the columns are VARCHAR type, then which operation will be faster:- inserting a new row or updating an existing row based upon some matching condition?
I'm having a bit of trouble with using the Scanner and the Printwriter. I start with a file like this (1 = amount of Houses in the file)
1 FOR SALE: Emmalaan 23 3051JC Rotterdam 7 rooms buyprice 300000 energylevel C
The user gets (let's say for simplicity) 3 options:
1. Add a House to the file, 2. Get all Houses which fullfil requirements (price, FOR SALE / SOLD etc.) and 3. Close the application.
This is how I start:
Scanner sc = new Scanner (System.in); while (!endLoop) { System.out.println("Make a choice); System.out.println("1) Add House"); System.out.println("2) Show Houses"); System.out.println("3) Exit"); int choice = sc.nextInt();
Then I have a switch for all of the three cases. I keep the scanner open, so Java can get the user input (house = for sale or sold, price = ... etc). If the user chose option 1, and all information needed is inputted and scanned, the House will be written to the file (which looks like what I typed above).
For this, I use try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("Makelaar.txt", false)))). This works perfectly (at least so it seems.)
If the user chose option 1, and all requirements are inputted and scanned, the Houses will be read (scanner) from the file and outputted. For this I use the same Scanner sc. This also works perfectly (so it seems atleast).
My problem is as follows: If a House has been added, I can only read the House(s) which were already in the file. Let's say I have added 2 houses, and there were from the start 3 houses. If option 2 is chosen, the first 3 houses will be scanned perfectly. An exception will be caught for the remaining 2 (just added) Houses. How can I solve this? I tried to close the Scanner, and reopening it, but apparently Java doesn't agree with this
How can I Cache the data I'm reading from a collection of text files in a directory using a TreeMap? Currently my program reads the data from several text files in a directory and the saves that information in a text file called output.txt. I would like to cache this data in order to use it later. How can I do this using the TreeMap Class? These are the keys,values: TreeMap The data I'd like to Cache is (date from the file, time of the file, current time).
import java.io.*; public class CacheData { public static void main(String[] args) throws IOException { String target_dir = "C:Files"; String output = "C:Filesoutput.txt"; File dir = new File(target_dir); File[] files = dir.listFiles();
I try to use below codes to convert Hex String "1111737999630745" to ASCII.
When I read the result in Notepad++ with HEX-Editor plugin, I find attached image which is different from above String, there is one additional c2 and I am quite confused.
Java Code:
public static void main(String[] args) throws IOException { Test strToHex = new Test(); File file = new File("D:/filename"); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile();
I need to write a program that combines everything I learned in my Java course from chapter 1-6 and 8 by Tony Gaddis at least with all the other chapters being bonus points, so I decided to write a program that tells you the binary to hex conversion or hex to ascii conversion. However I keep getting the following errors in my class, enums, and main program that I'm not sure about why. Please do not point out that the numbers in the case select are not what the hex values translate to because I know that, but I was trying to use more meaningful place holders temporarily:
These are the errors for main:
----jGRASP exec: javac BinToHex.java BinToHex.java:9: error: cannot find symbol Scanner keyboard = new Scanner(System.in); ^ symbol: class Scanner location: class BinToHex
[Code] .....
3 errors
----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.
Because of the error in the picture attached I am unable to show the remaining errors for the class and enumsjGrasp Save error for Ascii character import enum datatype.jpg
Here is the code for main:
import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.*; /** This program shows that you can binary to hex and hex to ascii. */ public class BinToHexToAscii
What is printed is much larger than what I've copy and pasted but I can't post it all here.
The error I get is:
Exception in thread "main" java.io.IOException: Stream closed at java.io.BufferedReader.ensureOpen(Unknown Source) at java.io.BufferedReader.readLine(Unknown Source) at java.io.BufferedReader.readLine(Unknown Source) at Map.importMap(Map.java:26) at Map.main(Map.java:44)
For part of my program, I am trying to ask the user for input on generating a number of random characters. I have already done this with integers and doubles, how would I do this for characters using ASCII values? Would I use the same format as I did for generating integers (Shown in code)?
import java.util.Random; import java.util.Scanner; public class NewNumberCharacter { public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner(System.in);
I am trying to figure out how to convert a string of ASCII code into char.I know that you can use (char) to convert it, but the issue is you cannot really just it for Strings.