Difference Between InputStream And InputStreamReader

Jul 11, 2014

I read that InputStream is used for byte based reading it reads 1 byte at a time.And InputStreamReader is used for charcter based reading so it reads one charcter at a time so no need to convert this first to int then read it.Here is reading using InputStream.

input=new FileInputStream("D:/input.txt");
int c;
while((c=input.read())!=-1)
{
System.out.print((char)c);
}

and here is reading using InputStreamReader

input=new FileInputStream("D:/input.txt");
reader=new InputStreamReader(input,"UTF-8");
int c;

while((c=reader.read())!=-1)
{
System.out.print((char)c);
}

so what is difference between InputStream and InputStreamReader in both case i have to use a Int and then read it and at the end if I want to print that data I have to cast that with "(char)c".So what is advantage of using InputStreamReader?

View Replies


ADVERTISEMENT

InputStreamReader Looking For File Location

Apr 26, 2014

The file (let's call it file.txt) is on the C: of my machine. I'm using :

System.out.print("Where is the file?: "); BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

And looking for the user to enter the location of the file in the console. How do I (the user) enter the path to the file in the console. I have tried everything... "C:file.txt", C:file.txt, and a million other combinations. Nothing seems to work. How does the console expect the file path to be written so it knows how to pick up the file?

View Replies View Related

How To Make Age Call In Java With Bufferedreader And Inputstreamreader

Aug 18, 2014

I am having problems in creating an age calculator in java. The only input is your name and date of birth. It means I need to incorporate the current date and make conditions. I am only allowed to use BufferedReader, InputStreamReader and IOException for import. I need to start with this and just add the conditions,

import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
public class ageactivity
{
public static void main (String[] args) throws IOException
{
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));

[code]...

I tried to add conditions but its not calculating the days.

View Replies View Related

How To Manually Put Data Into InputStream

Aug 23, 2014

I am new to programming in regards to I/O, channels, SSH, etc...

At the moment I am trying to transform the Shell.java program from the JCraft JSch examples; JSch - Java Secure Channel - Examples

The way in which I am trying to transform it is by instead of having the character input go into the channel automatically from the keyboard (refer to line 77 in Shell.java), I just want to pro-grammatically insert characters in to the channel at my discretion, so for example I have a string called unixCommand that I want to insert into the channel, and I don't want there to be any other way of inserting into the channel such as the standard input stream, so for example I'd have the statement <insert unixCommand to UNIX box at other side of channel> inserted somewhere after line 100 in Shell.java.

I was thinking that maybe I have to use some other InputStream object at line 77 when setting the channels input stream instead of System.in, but I am not sure how to do this (but really I'm not sure if I'm even on the right tracks?). I believe all this confusion may be down to a misunderstanding with the general concepts involved with channels and I/O ...

View Replies View Related

How To Manually Put Data Into InputStream

Aug 23, 2014

I am trying to transform the Shell.java program from the JCraft JSch examples : [URL] ....

The way in which I am trying to transform it is by instead of having the character input go into the channel automatically from the keyboard (refer to line 77 in Shell.java), I just want to pro-grammatically insert characters in to the channel at my discretion, so for example I have a string called unixCommand that I want to insert into the channel, and I don't want there to be any other way of inserting into the channel such as the standard input stream, so for example I'd have the statement <insert unixCommand to UNIX box at other side of channel> inserted somewhere after line 100 in Shell.java.

I was thinking that maybe I have to use some other InputStream object at line 77 when setting the channels input stream instead of System.in, but I am not sure how to do this (but really I'm not sure if I'm even on the right tracks?). I believe all this confusion may be down to a misunderstanding with the general concepts involved with channels and I/O.

View Replies View Related

Continuously Reading From Socket InputStream

Feb 26, 2014

I'm writing a really simple 1 on 1 chatting program thing using java.net.Socket and reading each other's messages b using writeUTF() and readUTF() of java.io.DataOutputStream and java.io.DataInputStream. Thing is, I wanna write a thread for both sides to continuously read from their respective socket's input streams while ignoring the lack of data coming through like when one user is not sending a message or something. I've written a dumbed down version of this that only reads one message from only one side and another one that sends a file, both of which work fine, I guess.

I'm using java.util.Scanner for user input, if that's acceptable, for I am not too familiar with Java's other readers. Also, I just started teaching myself about java.net.Socket, so I may not be too familiar other than the basics like how to set up a connection and how to send data using the getOutputStream() member function and stuff like that.

View Replies View Related

Servlets :: InputStream To Character Array Char In Java

Jun 27, 2014

I had a Rest web service call and get InputStream.Now i want to Write Input Stream to PrintWriter of servlet.So that it can be downloaded.I am able to write String and file can be downloaded using following code, i want it to work for Input streamFollowing is code:

response.setContentType("application/x-download");
response.setHeader("Content-Disposition", "attachment; filename="" + name + ".pdf"");
response.getWriter().write(is);

Write can take following:
write(String)
write(char[])
write(int)
write(String, int len, int off)
write(char[], int len, int off)

I think char[] will not harm PDF file which is going to download in it

View Replies View Related

I/O / Streams :: JasperAssistant 2.4.2 Error Loading Object From InputStream

Dec 4, 2014

I have upgraded to myeclipse 10.7 ,java "com.sun.java.jdk.win32.x86_64_1.6.0.013" and Struts 2.1 (Right now using Struts 1.1 support) from myeclipse 10.7 ,java 1.4 and Struts 1.1. I installed jasperassistant 2.4.2 plug-in using jasperReports 2.0.2 (My old report files were using same version).

All files compile successfully in new environment but when I export I get following error Export to PDF

a. Reports having no crosstab
"Java.lang.NullPointerException"

b. Reports reports having crosstab
"Error loading object from InputStream"
java.io.InvalidClassException: net.sf.jasperreports.crosstabs.base.JRBaseCrosstabGroup;

Export to EXCEL

a. Reports having no crosstab
java.lang.NullPointerException

b.Reports reports having crosstab
java.lang.NullPointerException

All files are at correct location....

View Replies View Related

Parsing Multipart Message With Byte Array InputStream - Loosing Information?

Feb 20, 2014

I just wrote a small but working code to parse a multipart message with two files binary encoded.

Problem is, after splitting the content of the files is reduced to normal "alphabetic" digits, and i dont know why.

I just appended my source code and a test file ( multipart ). And the result of my parsing. (part_0 = json, part_1 = file, part_2 = file)

Unfortunately, i dont know, if the Spring FW provides an easier way of doing so at all. Haven't found it yet.

Java Code:

String requestUrl = "http://localhost:8888/";
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
HttpEntity<String> entity = new HttpEntity<String>("test");
ResponseEntity<byte[]> response = restTemplate.exchange(requestUrl, HttpMethod.GET, entity, byte[].class);

[Code] .....

View Replies View Related

Difference Between Eclipse And JDK?

Feb 27, 2014

I'm not sure if that's the right place to ask

But I am a bit confused:

I know that JDK means "Java Development Kit" , but isn't Eclipse the same thing? (so why it's called "IDE"?)

Or maybe Eclipse is a type of JDK?

Or actually JDK and Eclipse are 2 different things

View Replies View Related

JSF :: Difference Between EventHandler And ActionListener?

Feb 11, 2015

What Is the difference between an ActionListener and an EventHandler ?

button.addActionListener(new ActionListener() {
button.setOnAction(new EventHandler<ActionEvent>() {

View Replies View Related

Difference Between Unused And Unread

Sep 19, 2014

exact difference between

1. unread fields
2. unused fileds

in java

View Replies View Related

Difference Between Abstract And Inheritance

Dec 16, 2014

I am new to java i dont understand the difference between the abstract and inheritance i mean we use the abstract class with extends with other class name ,even we do that same in the inheritance pls tell me main difference between abstract and inheritance...

View Replies View Related

Difference Between Java And JavaScript?

Jul 11, 2014

how to program in Javascript, I am wondering what are the advantages and disadvantages OR pros/cons of using JS versus say a language like Java?

View Replies View Related

How To Calculate Difference Between Two Dates

Oct 19, 2014

I have been tasked with creating an invoice (school assignment). Part of the calculations is creating an interest depending on the amount of days between the current date entered, and invoice date entered (The program prompts the user to enter both the current and invoice dates by asking for the day, month and year).

We are also supposed to set the contructor to a default date of 1/1/1900.. but I don't know how or where to code that.

How to calculate the difference between the CurrentDate and Invoice. I have displayed the dates to the user as follows.

public void displayDate() {
System.out.println("
Today's Date: " + month + "/" + day + "/" + year);
}
public void displayInvDate() {
System.out.println("
Invoice Date: " + invMonth + "/" + invDay + "/" + invYear);

View Replies View Related

Difference Between LinkedList And ArrayList

Feb 19, 2014

I have just begin to understand collections in Java. I read about the differences between LinkedList and ArrayList but have several doubts on it. I have mentioned them below

1) Why retrieving in ArrayList is faster then LinkedList?. Since both have the get method how does performance differ?.

2) How does re-sizing happens internally in ArrayList when a item is added or removed?. How slow this is compared to the pointer re-shuffling in LinkedList when a item is added or removed?.

View Replies View Related

Difference Between Protected Or Default

Mar 28, 2015

I am new in java. Is there any difference between protected or default when we are talking about one package?

View Replies View Related

JSP :: Difference Between Jspf And Tags?

Mar 12, 2015

I know jspf is a jsp fragment, but can't a tag also serve as a jsp fragment?

View Replies View Related

Difference Between Application And Applet?

Apr 13, 2014

Can explain difference between applet and application?

What are differences in code? How to write application?

What are differences in use? I looked for some answers, but I can't understand what they are talking about.

For example:

Application:

Called as stand-alone application as application can be executed from command prompt

Applet:

Requires some third party tool like a browser to execute

But... While I export applet in exclipse I can use it without any browser, just like application(as I and avarage user knows it).

Ok, I understand difference like "Applets cannot read from or write to hard disk files."

So. What should I use while creating what?

For example, something as simple as windows calc, some 2d simply platformer, some more expanded app, like idk, spotify or media player or whatever?

Since after update 51 of java web applets are nearly useless(as I know, maybe I'm wrong?), what is better?

Can application have GUI or it is only applets thing(stupid question?)?

Where can I find any application tutorial? Everything that I found was for applets. Why?

View Replies View Related

Difference Between JavaFX And Swing?

Jan 28, 2014

I know that oracle has released a statement saying that JavaFX will eventually replace Swing. What is the advantage of JavaFX? The new format, using "stage" instead of JFrame, seemed weird. Why is this change necessary? What benefit do we reap from JavaFX that Swing does not have?

View Replies View Related

Difference Between Element And Index?

Apr 17, 2014

Im working on my homework and it mentioned element for one exercise and an index in another, what is the difference, If Any, Between An Element And An Index?

View Replies View Related

What Is Difference Between Float And Double

Jan 31, 2011

What is the difference between float and double?

View Replies View Related

Difference Between JavaSE8 And Its Predecessors?

Jul 14, 2014

If I am making an application using Java SE8 and I use new concepts of JavaSE8 like "Lambda Expressions" and "Default Methods".

After completing my application I give it to client who are using Java Platform less than 8 like Jdk1.7._; then will this application will work fine as it is working on JavaSE8.

a JavaSE8 application works well on Java SE7 platform.

View Replies View Related

Difference Between Interpreter And Compiler?

Aug 13, 2014

I am reading a java book and find a theory about Interpreter and Compiler. explain different between them?

View Replies View Related

Difference In Days Between Dates

Dec 5, 2013

I know this has been covered before but none of the answers made sense to me. I'm hoping there is an easy way to do this. I have 2 user inputted strings that I have converted to dates and I just want the difference in days.

My code :

import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Scanner;
import java.text.ParseException;
public class DateTest {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws ParseException {

[Code] ....

Apparently I can't just subtract the dates like I would in VB.

View Replies View Related

Difference Between REST GET And Httpget?

Dec 2, 2014

But while searching i came across 2 different implementation.. One is this and other is this , where httpget is used..

So are these same ? When we talk about Restful, is the 2nd implementation valid ?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved