How to read a text file from other machine???
I have a text file located in local machine. I use th e code below to retrieve data from that particular text file.
String realPath = (String)getServletContext().getRealPath("");
BufferedReader holsFile = new BufferedReader(new FileReader(realPath + "/webpages/holidays.txt"));My question is , how could I retrieve the records from the tsxt file if the file is located in another machine or webserver?
Thanks for advanced.
It's ok to be new.
The answer is yes. (But I'll let you look in the javadoc to see which package it's in).
Also it may be worth understanding that there is no such thing as a "function" in java, operations are termed "methods". To go further, you should realise that URL is a class not a "function" or method. The parentheses mean you're calling the constructor.
HTH
/k1
Similar Messages
-
How to read a text file from a Jar file
Hi
How can I read a text file from a Jar file?
Thanx in advance..thanx
helloWorld it works.damn, I didn't remove it fast enough. Even if it is urgent, it is best not to mention it, telling people just makes them take longer. -
How to read a text file from Visual Composer
Hi VC Experts,
Please suggest me how can we read a textfile from the local machine and pull the data from Visual Composer.
Regards
KiranHy kiran, is not possible to read data from flat file and put it in visual composer but you can :
1) load this file in BI by ETL, for example on DSO object and then you can create a bex query to retrive the data
2) if you want display the content of this file , you can use KM.
Regards,
Andrea -
How to download a text file from the server
hi everyone,
can anyone tell me how to download and read a text file from the server and saved in into resource folder.
with regards
pallaviits really easy
To read from server, use something like:
HttpConnection connector = null;
InputStream inp_stream = null;
OutputStream out_stream = null;
void CloseConnection()
if(inp_stream!=null)inp_stream.close();
inp_stream=null;
if(out_stream!=null)out_stream.close();
out_stream=null;
connector.close();
connector = null;
public void getResponse(String URL,String params)
try
if(connector==null)connector = (HttpConnection)Connector.open(URL);//URL of your text file / php script
connector.setRequestMethod(HttpConnection.POST);
connector.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.1");
connector.setRequestProperty("content-type", "application/x-www-form-urlencoded");
//connector.setRequestProperty("charset","windows-1251");
//*** If you need to send ("arg1=value&arg2=value") arguments to script use this:
out_stream = connector.openOutputStream();
byte postmsg[] = params.getBytes();
out_stream.write(postmsg);
int rc = connector.getResponseCode();//in any case here connection will be opened & closed
if (rc != HttpConnection.HTTP_OK)
CloseConnection();
throw new IOException("HTTP response code: " + rc);
inp_stream = connector.openInputStream();
int pack_len = inp_stream.available();
byte answ[]=new byte[pack_len];
inp_stream.read(answ);
CloseConnection();
ProcAnswer(answ);//process received data
catch(Exception ex)
System.err.println("ERROR IN getResponse(): "+ex);
} And you can read from resource file like
public void loadFile(String filename)
DataInputStream dis = new DataInputStream(getClass().getResourceAsStream("/"+filename));
String str="";
try
while (true)
ch = dis.read();//read character
if(ch=='\r')continue;//if file made in windows
if(ch=='\n' || ch==-1)//end of line or end of file
if(str.length()==0)continue;//if empty line
//do some thing with "str"
if(ch==-1)break;//it was last line
str="";//next line
continue;
str+=(char)ch;
dis.close();
catch (Exception e)
System.err.println("ERROR in loadFile() " + e);
}Welcome! =)
Edited by: MorskoyZmey on Aug 14, 2008 3:40 AM -
Reading a text file from a remote host. Authentication required.
Hi frnds,
I have to read a text file "config.txt" from a remote host "HOSTNAME". File is shared in a folder - "FOLDER" .
If the folder is shared with no password protection then it works. But if the folder is password protected the code is unable to read the file.
I know the UserName and PassWord of the shared folder. How to code for this.
I don't want to share the Folder to everyone without a password.
Kindly Help.
try {
FileReader fr=new FileReader("\\\\HostName\\folder\\config.txt");
BufferedReader br=new BufferedReader(fr);
String s=null;
while((s=br.readLine())!=null)
/* One line is read */
fr.close();
catch(Exception e)
throw new Exception("Exception in ConfigConstants."+e.toString());
urs
Mishraok.. let me define it clearly...
By using ftp as a protocol how can I read a text file
in remote machine........ kindly do reply....Have a look at this article:
http://www.javaworld.com/javaworld/jw-04-2003/jw-0404-ftp.html
and what are the prerequisities that are needed for
such a type of operation.....(At least) an FTP server should be running on the machine where the text file resides.
Message was edited by:
prometheuzz
Oh, you should have your keyboard fixed: the full stop key seems to be stuck, you have a lot of trailing ..... after each sentence. -
How to read a text file using Java
Guys,
Good day!
Please help me how to read a text file using Java and create/convert that text file into XML.
Thanks and God Bless.
Regards,
I-Talkpublic void fileRead(){
File aFile =new File("myFile.txt");
BufferedReader input = null;
try {
input = new BufferedReader( new FileReader(aFile) );
String line = null;
while (( line = input.readLine()) != null){
catch (FileNotFoundException ex) {
ex.printStackTrace();
catch (IOException ex){
ex.printStackTrace();
}This code is to read a text file. But there is no such thing that will convert your text file to xml file. You have to have a defined XML format. Then you can read your data from text files and insert them inside your xml text. Or you may like to read xml tags from text files and insert your own data. The file format of .txt and .xml is far too different.
cheers
Mohammed Jubaer Arif. -
Read a text file from DB directly (don't use PLSQL).
how can I Read a text file from DB directly (don’t use PLSQL). ?
If there is a known structure, you could use External Table access and query that "file" as any table.
Nicolas. -
How to upload a text file from a shared folder and provide an o/p
how to upload a text file from a shared folder and provide an o/p containing the details in each order in the text file
Hi,
Use <b>GUI_UPLOAD</b> to upload a text file from a shared folder.
Use <b>GUI_DOWNLOAD</b> to download data in a file on the presentation server or use <b>OPEN DATASET, TRANSFER</b> and <b>CLOSE DATASET</b> statements to download data to the application server.
Now, I hope the code for data fetching, if required, is already present in the report.
Reward points if the answer is helpful.
Regards,
Mukul -
How to read several text files at a time
Dear all
Read and write one text file is not a problem, but what confusies me is how to read several text files at one time, in the meanwhile,
is it possible to display the name of the text file?
For example, assuming I want to load file" cha 1, cha 2 , cha 3, " at one time and show their names, how to hadle with it
I have reviewed some files and it is not helpfulEither with a 'for' loop like in the lib you have attached, or like this attached VI
that's it
Message Edited by devchander on 05-30-2006 05:11 AM
Attachments:
MULTIPLE READ.vi 44 KB -
Reading a text file from a URL
I am having problems trying to read a text file from a URL.
This is the code i have been using:
package Java;
import java.net.*;
import java.io.*;
public class Main_1 {
public static void main(String[] args) throws Exception {
URL myAddress = new URL("http://www.geocities.com/simonrobinson1/java/farrago.txt");
BufferedReader in = new BufferedReader(
new InputStreamReader(
myAddress.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
but it returns an error saying:
java.net.NoRouteToHostException: Operation timed out: no further information
at java.net.PlainSocketImpl.socketConnect(Native Method) .....etc etc.
Is this just a problem due to my network or is there something wrong with my code ????Altho you can access the file by typing the URL in a browser, geocities being a free web-hosting service don't like you to access the materials without seeing their ads. You have to find a way to trick it into thinking that you are indeed coming in from a web browser even tho you aren't.
V.V. -
Sample code to read a text file from UNIX directory.
I am using 9i Developer Suite, application server is 9.0.4. I want some help on how to read a flat file from UNIX environment. A sample code could be very helpful.
In windows, i use this kind of code:-
I declare an object & then write to a file using these sample staements:-
file_handle text_io.file_type;
filename := 'd:\ran\egs\uninvoiced.txt';
file_handle:=text_io.fopen(filename,'w');
text_io.put_line(file_handle, 'MOBILE NO '||'COUPON NO ' || 'DATE');
I hope, my question is clear. Please help in solving the doubt.
Regards.filename := 'd:\ran\egs\uninvoiced.txt';This is a Windows directory, so it won't work on Unix.
For the rest of the code: see examples in the Forms Builder Online Help. -
How to Read a CAB File from JAVA?
Hi,
Anyone knows how to read a CAB File from java. I need to read a property file of txt file that is packaged in CAB file & then based on that, I have to do processing. Is there anyway to do it.
I had tried using java.util.zip.ZipFile Class, but it does work for JAR, but not for CAB.
siva.Perhaps there's something in the Cabinet SDK that will help:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncabsdk/html/cabdl.asp -
How to read a text file through pl/sql
How to read a text file through pl/sql
pl/sql runs inside the database. so your file also should be on the database server file system for you to be able to read.
check out UTL_FILE package. This is the database package to read/write files on the database server. -
How to read two text files using the Read from spreadsheet.vi and then plot it
I need to read two text files using the read from spreadsheet function and then plot these files over time.
The file with the .res extention is the RMS values (dt and df) and the second file contains the amplitude of a frequency spectrum.
I really appreciate any help..thanks
Attachments:
RMS.txt 1 KB
FREQUENCY.txt 1 KBFrom NI Example Finder:
Write to Text File.vi
Read from Text File.vi
Jean-Marc
LV2009 and LV2013
Free PDF Report with iTextSharp -
How to read a text file located on other PC.
Hi,
i've to read a text file using javabut file is not at my PC but it is on a different PC.I know the IP Address of that PC. But i m not able to connect to it. Plz. provide any suggession with some sample code if possible.
Thx.Do you have access to other host or no? Are you going to write software for both hosts or planning to use existing server?
Actually you can use any known protocol or write your own.
Maybe you are looking for
-
New MBP changes resolution when logging out
I have a brand new MacBook Pro 2.2 GHz Intel Quad Core i7 with a high resolution glossy display which have a native resolution of 1680x1050 pixles. But almost every time after I log out the resolution changes to 1440x852. In System Settings the resol
-
i predownloaded an album on itunes, when i came on my computer the songs were there but not fully downloaded.. when i go to click them to download again, it says i have a network error, its error -3150. i previously called and they said it had to do
-
How do I make a black and white portrait with piercing color eyes or red lips
I am frustrated thus far with this PS elements 10 and trying to get answers on the internet is frugal as I've come across a solution which doesn't assist me with elements 10. Please help before I return this product
-
LMS3.2 - Service Temporarily Unavailable
Hi there Our Windows Cisco Works Server ran out of disk space, I freed up some space and rebooted the server. After I restarted the server I now get the following message when trying to use a web browser to connect - Service Temporarily Unavailable T
-
Contacts app only shows ICE and Myself
Help! When I go to Contacts, "Contacts Setup" "Sync with online accounts" and "Import contacts" are displayed. Already tried them all. I cannot get to view all my contacts from Facebook, Google+, etc! Even if I add new contacts, later on nothing stil