How to get InputStream from String ?
Hi !
I want to get InputStream object from String.
String str = "balabalabala";
InputStream stream = getInputStream(str);
How to realize getInputStream(str) function ?
Thanks!
The preferred method nowadays is to use Readers and Writers for String data - hence StringReader(String). If you're going to operate on the InputStream directly, then I'd modify your code to use the Reader calls and go that route.
If, however, you need to pass the InputStream to some other piece of API that requires an InputStream instead of a Reader, then the ByteArrayInputStream is probably your best bet. StringBufferInputStream is deprecated because it doesn't work reliably in the face of many character encodings.
Speaking of encodings - never call Strng.getBytes() - always use the getBytes(character-encoding) version, so you KNOW what encoding you're getting!
Grant
Similar Messages
-
How to get substring from string starting from the end of string
Hi
How to cut from string:
$A=C:\ClusterStorage\Volume1\WXP-plwropc300\Virtual Hard Disks\WXP-PLWROPC300_EE20E00F-315E-4781-A6DE-68497D4189B8.avhdx
this substring (name of VHD file): WXP-PLWROPC300_EE20E00F-315E-4781-A6DE-68497D4189B8.avhdx
This script should be universal so the best way to be cut all leters from the end of string $A till get the first mark \
Thank you for help.
Tomasz
Kind Regards TomaszPS > Split-Path 'C:\ClusterStorage\Volume1\WXP-plwropc300\Virtual Hard Disks\WXP-PLWROPC300_EE20E00F-315E-4781
-A6DE-68497D4189B8.avhdx' -leaf
WXP-PLWROPC300_EE20E00F-315E-4781-A6DE-68497D4189B8.avhdx
PS >
That is what "Split-Path" is for:
¯\_(ツ)_/¯ -
How to get InputStream from a file with absolute path?
Hi, guys:
If I have file with a absolute path that may be inside/outside
my Eclipse plugin, I want to get an InputStream from it. It just keeps giving me null for "is":
String absFilePath = "/D:/my_dir/.../sample_file.txt";
InputStream is = getClass().getResourceAsStream(absFilePath);
regards,Don't use resource as stream if you have an absolute path, use FileInputStream.
-
How to get substring from string using index?
hi,
here i am having string ,
i want the pullareddy from below line ,
i know how to get from substring.
but i want to get the above using "index",
can any help how to do it?
String str1="janapana,pullareddy, in malaysia";
jpullareddyget the start index with indexAt("pullareddy")
get the end index with adding the length of the word to the start
get the char[] of str1 with toCharArray()
make a new string with the chars from start to end index. -
How to get InputStream from JTextArea.getText() string?
hello,
well the postname pretty much says it, i need to get an InputStream for the String of a JTextArea.
thing is, i want to save the string in a textfile, but the new line isnt recognized when i write it to the file.
FileWriter fw = new FileWriter ("text.txt");
fw.write(editField.getText()); // editField is my JTextArea instanceso i thought of doing smth like this
String lineSeparator = System.getProperty("line.separator");
// somehow getting the InputStream for my editField and save it in "is"
BufferedReader br = new BufferedReader(new InputStreamReader (is));
String line;
while ((line = br.readLine()) != null) {
fw.write(line);
fw.write(lineSeparator);
}pSaiko wrote:
hello,
well the postname pretty much says it, i need to get an InputStream for the String of a JTextArea.
thing is, i want to save the string in a textfile, but the new line isnt recognized when i write it to the file.
FileWriter fw = new FileWriter ("text.txt");
fw.write(editField.getText()); // editField is my JTextArea instanceso i thought of doing smth like this
String lineSeparator = System.getProperty("line.separator");
// somehow getting the InputStream for my editField and save it in "is"
BufferedReader br = new BufferedReader(new InputStreamReader (is));
String line;
while ((line = br.readLine()) != null) {
fw.write(line);
fw.write(lineSeparator);
This is very simple, it isn't buffered, but it should work for you.
Sting s = editfield.getText();
for(int i=0; i<s.length();i++) fw.write((int)s.charAt(i));
fw.flush();
fw.close(); -
I have a String contains records seperated by tab.How cani break up into individual record and get them
Bill Mor 1234 US-TEXAS 56
John Cruz 4567 UK-EDH 45
I need
Bill Mor
1234
US-TEXAS
56
then
John Cruz
4567
UK-EDH
45String[] splitLine = line.split("\t");
-
How to get InputStream of uploaded file from request?
The situation:
Client is uploading xml file to server.
<form METHOD=POST ENCTYPE = "multipart/form-data" action="SendFile" accept="text/xml">
<input type="file" name="SentFile" />
<input type="submit" value="go"/>
</form>Then I need to parse data from file.
I want to use method javax.xml.parsers.DocumentBuilder.parse(InputStream is)
But, how to get InputStream of uploaded file from request?You cannot get the InputStream of the uploaded file directly. The InputStream you can obtain from request.getInputStream() contains a lot of other data as well as the uploaded file. You will have to parse the data in the InputStream to find the data that belongs to the file.
A short cut is to use the HTTP Multipart File Upload available from www.jenkov.com. It simplifies file upload and makes it easy to obtain an InputStream for only the uploaded file. It also handles upload of multiple files. It is free, open source, Apache license, so if it doesn't fit your needs, you can always read the code and see how it works. Then write your own upload servlet. -
How to get CLOB from stored procedure via StoredProcedureCall
hi all
I got "sp" on server : procedure get_text(p_in in varchar2, o_list out clob);
in code:
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName("get_text");
call.addNamedArgumentValue("p_in", new String("MyList"));
call.addNamedOutputArgument("o_list"); // <- out CLOB
Vector v = (Vector)this.m_UnitOfWorkt.executeSelectingCall( call ); // <- here I got error
but if o_list is varchar is all ok
so how to get data from clob?
Please help
Regards
KrzysztofPost Author: achaithanya
CA Forum: Data Connectivity and SQL
I'm connecting to database through stored procedure only.We have sybase installed on our local system so that we are given permissions only to access the stored procedures.When u see the fields in CR XI i.e Field explorer you are able to see only 1st result fileds.I connected to sybase and there i'm able to see the output of 1st & 2nd Result set.
Regards,
Chaithanya. -
How to get coordinates from Google Map
I wonder how to get coordinates from Google Map to JavaFX application when click has occured. Here is an example of code:
public class JavaFXApplication extends Application {
public void showCoordinates(String coords)
System.out.println("Coordinates: " + coords);
@Override public void start(Stage stage)
final WebView webView = new WebView();
final WebEngine webEngine = webView.getEngine();
webEngine.load(getClass().getResource("googlemap.html").toString());
webEngine.getLoadWorker().stateProperty().addListener(
new ChangeListener<State>() {
@Override
public void changed(ObservableValue<? extends State> ov, State oldState, State newState) {
if (newState == State.SUCCEEDED) {
JSObject window = (JSObject) webEngine.executeScript("window");
window.setMember("java", new JavaFXApplication());
BorderPane root = new BorderPane();
root.setCenter(webView);
stage.setTitle("Google maps");
Scene scene = new Scene(root,1000,700, Color.web("#666970"));
stage.setScene(scene);
stage.show();
public static void main(String[] args){
Application.launch(args);
// googlemap.html file
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 100%; background-color: #666970; }
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(40.75089, -73.93804);
var myOptions = {
zoom: 10,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
panControl: true,
navigationControl: true,
streetViewControl: false,
backgroundColor: "#666970"
var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
document.map = map;
google.maps.event.addListener(map, 'click', function(event) {
//java.showCoordinates(event.latLng); ???
map.setCenter(location);
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>Edited by: krbltik on 03.10.2012 22:59Hi, welcome!
You may also have a look at GPS Info Qt, available for free at Ovi Store: http://store.ovi.com/content/165671
GPS Info Qt is a nice Qt app. I have it on my C6-01 and I like it.
Regards. -
How to get Text from (.txt) file to display in the JTextArea ?
How to get Text from (.txt) file to display in the JTextArea ?
is there any code please tell me i am begginer and trying to get data from a text file to display in the JTextArea /... please help...public static void readText() {
try {
File testFile = new File(WorkingDirectory + "ctrlFile.txt");
if (testFile.exists()){
BufferedReader br = new BufferedReader(new FileReader("ctrlFile.txt"));
String s = br.readLine();
while (s != null) {
System.out.println(s);
s = br.readLine();
br.close();
catch (IOException ex){ex.printStackTrace();}
}rykk -
CallableStatement: how to get prepared call string?
How can I get the parameter string that is set via prepareCall() from a CallableStatement?
String call = "{call sp_irecord (?,?,?)}";
CallableStatement cs = connection.prepareCall(call);
//later, when 'call' is not known but cs:
String originalCall = csc.get???();
//how to get the call string from the callable statement?i don't mean the parameter names or values, i mean the string that you set with the prepareCall() method:
String call = "{call sp_irecord (?,?,?)}";
CallableStatement cs = connection.prepareCall(call);
System.out.println("Call string: "+cs.getCallString());with the method getCallString() (that i invented and that i'm looking for) should return the exact string. The output of the example above should be:
Call string: {call sp_irecord (?,?,?)} -
how to get photos from mac to iPhone 6? when i try it just comes up iCloud instead of my photos
Make sure Settings > iCloud > Photos > iCloud Photo Library (Beta) = "Off"
Then sync your iPhone using iTunes and make sure your sync settings for photos are set correctly in iTunes. -
I got a new computer and don't know how to get music from ipod touch to itunes library
I recently got a new computer and don't know how to get music from my ipod touch to show on my itunes library.
You need to transfer the iTunes folder from the old computer to the new one.
iTunes: How to move your music to a new computer (Mac or Windows):
http://support.apple.com/kb/HT4527 -
I have a new MacBook Air and don't know how to get info from my USB stick and get info from my SD card. Can anyone help, please?
Plug the stick and/or card into the appropriate slots on the side of your Air. Do you see icons for the devices appear on the desktop? Click into them to see what files are there.
Matt -
How to get data from a USB-UIRT device using Labview?
How to get data from a USB-UIRT device using Labview?
I'm trying to get data from a USB-UIRT device, is it posible with Labview?
I really appreciate your help,
thanksYou may want to contact the developer of the device for the API and DLL.
http://65.36.202.170/phpBB2/viewforum.php?f=3
Maybe you are looking for
-
There are about 8 songs on a playlist that are listed in the playlist library but when I try to transfer them to the playlist, it states that they can't be transferred because the original file could not be found. Then it asks, do you want to locate
-
Mini Displayport to HDMI doesn't work!
Hi 2 all! I bought a Mini Displayport to HDMI cable (Manufacturer Artwizz) a few weeks ago and last week I have received the new Macbook Pro 13''. I tried to connect the Macbook with my LCD TV and Beamer through this cable but both didn't work! After
-
We use the BAPI_ROUTING_CREATE for the copy of routings from one system to another via ALE. When we do this for relatively easy BOM's (not to many levels), this works fine. When we do this for large BOM's (more than 5 levels), the component assignm
-
How to play *.avi files in solaris10 sparc
hi frnds can some body tell me how to play avi files in solaris or is thr any binary packages ( but plese dont tell me abt source files i am fed up of compiling :) & ) if any binary packages r avilable please tell me or how to play in solaris 10 spar
-
I was successful in setting up sync between my Eee pc and Atrix 4G. This weekend i started getting an unknown error and re-trying the sync does not clear it. I often had to retry the sync in the past but i assumed it was because of all the network ac