How to read text file line by line...?
how to read text file line by line, but the linefeed is defined by user, return list of string, each line of file is a item of list?
please help me.
Thanks very much
Brynjar wrote:
In Groovy, you would do something like:
linefeed = "\n" //or "\r\n" if the user chose so
lines = new File('pathtofile').text.split("${linefeed}")This is one of the things that has always annoyed me about Sun's sdk, i.e. the lack of easy ways to do things like that. You always end up making your own utilities or use something like Apache's commons.io. Same goes for jdbc and xml - I'll wait for appropriate topics to show how easy that is in Groovy :)I generally agree, but what I really don't like about the Groovy text-file handling niceties: They don't care about encoding/always use the default encoding. And as soon as you want to specify the encoding, it gets a lot more complex (granted, it's still easier than in Java).
Similar Messages
-
Step by Step"How JSP read text file :
Hi ,
Any one know or have a good site to show step by step how JSP read text file.
TQ.There is no difference Between reading a text file from JSP and reading a text file from Java.
Just follow the same steps for JSP also. -
How to read a file line by line in UTL
Hi All,
DECLARE
fileID UTL_FILE.FILE_TYPE;
strbuffer VARCHAR2(100);
BEGIN
fileID := UTL_FILE.FOPEN ('DR', 'New.txt', 'R');
UTL_FILE.GET_LINE (fileID, strbuffer);
dbms_output.put_line(strbuffer);
END;
By this program I can read only first line of the file. I want to read the file line by line.
Thanks
Suniltry this
DECLARE
fileID UTL_FILE.FILE_TYPE;
strbuffer VARCHAR2(100);
BEGIN
fileID := UTL_FILE.FOPEN ('DR', 'New.txt', 'R');
if utl_file.is_open(fileID) THEN
loop
UTL_FILE.GET_LINE (fileID, strbuffer);
dbms_output.put_line(strbuffer);
if strbuffer IS NULL THEN
exit;
end if;
end loop;
end if;
END;note: untested. -
How to read text file content in portal application?
Hi,
How do we read text file content in portal application?
Can anyone forward the code to do do?
Regards,
AnaghaCheck the code below. This help you to know how to read the text file content line by line. You can display as you require.
IUser user = WPUMFactory.getServiceUserFactory().getServiceUser("cmadmin_service");
IResourceContext resourceContext = new ResourceContext(user);
String filePath = "/documents/....";
RID rid = RID.getRID(filePath);
IResource resource = ResourceFactory.getInstance().getResource(rid,resourceContext);
InputStream inputStream = resource.getContent().getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line = reader.readLine();
while(line!=null) {
line = reader.readLine();
//You can append in string buffer to get file content as string object//
Regards,
Yoga -
How to read text file contain chinese character ?
Hi XI Expert,
I have scenario to read text file contain Chinese Character using sender file adapter. but every i was check from sxmb_moni all the chinese character looks different. and also the target file also i has changes.
Please advise me how to maintaine the chinese character in PI 7.0 SP17.
Thank You and Best Regards
FernandHi,
Refer these threads..
Receiver file adapter corrupting characters
Problem in converting special characters in input text file
Here is one more useful guide..
https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/502991a2-45d9-2910-d99f-8aba5d79fb42
Regards,
Sarvesh
Edited by: Sarvesh Singh on Nov 17, 2008 3:47 PM -
Dear Everyone
I have coding below.
{color:#3366ff}*Text file scores.txt*
{color}1 1 1
2 2 2
*{color:#3366ff}Java class jtableone.class{color}*
import javax.swing.*;
public class jtableone extends JApplet {
public static void main(String[] args) throws Exception {
{color:#ff0000}//Read file scores.txt{color}
java.io.File file = new java.io.File("scores.txt");
Scanner input = new Scanner(file);
while (input.hasNext()){
String id = input.next();
String firstname = input.next();
String lastname = input.next();
{color:#ff0000}//System.out.println(id +" "+ firstname +" "+ lastname);
{color}}
input.close();
{color:#ff0000}//Crearte JTable{color}
private String[] columNames =
{"ID", "First Name", "Last Name"};
private Object[][] data = {
//{"12", "Tom", "Clark"},
//{"13", "helen", "Tan"}
{color:#ff0000}//Display JTable{color}
private JTable jTable1 = new JTable(data, columNames);
public jtableone(){
add(new JScrollPane(jTable1));
Can you tell me What i do next?
Create a Object[][] data which can read text file.
Thanks
sevenlonsevenlon wrote:
Can you tell me What i do next?How are we supposed to know? We have no knowledge of what your assignment is.
Create a Object[][] data which can read text file.Then do that. Create the 2D array and store the data in it.
Also when posting code use code tags. Paste code, highlight it and click CODE button. -
How to read text file efficiently?
I use CharBuffer to read text file:
private List<String> load() throws IOException {
final String B = "<BODY>";
final String E = "</BODY>";
List<String> docs = new ArrayList<String>();
for (File file : files) {
FileReader reader = new FileReader(file);
CharBuffer buffer = CharBuffer.allocate(BSIZE);
StringBuilder sb = new StringBuilder();
while (reader.read(buffer) != -1) {
char[] dst = new char[buffer.length()];
buffer.get(dst);
sb.append(dst);
buffer.clear();
String s = sb.toString();
System.out.println(file + ": " + s.length());
int start = 0;
int i, j;
while ((i = s.indexOf(B, start)) != -1) {
j = s.indexOf(E, i + B.length());
docs.add(s.substring(i + B.length(), j));
start = j + E.length();
//System.out.printf("%d %d %d%n", i, j, start);
return docs;
}The file size is 1324350, but the code say it is 772802.
What's wrong with this code?
I want to read text file as quickly as possible.
Is this code the right way to read file?
Should I use FileReader or nio Channel and ByteBuffer?
Any suggestions are welcome!You are reading the file as if it were encoded in UTF-16. Each character uses two bytes so you have half the number of characters as you had bytes.
The following code reads an entire file in one hit.
public static String readText(File file) throws IOException {
byte[] bytes = new byte[(int) file.length()];
DataInputStream dis = new DataInputStream(new FileInputStream(file));
try {
dis.readFully(bytes);
} finally {
dis.close();
return new String(bytes, "UTF-8"); // or whatever your file encoding is.
}But you can still have less characters than bytes if there are any non ASCII-7 characters. -
HI,,,How to read text file from my emulators root
hi friends,
Actully i m having problem with file connection i.e. i cant read text file from my root of the emulator.....
i have tried like this...
plz help me out
String uri = "file:///C:/WTK22/appdb/DefaultColorPhone/filesystem/root1/New Folder/main.txt";
InputConnection conn = (InputConnection)Connector.open( uri,Connector.READ );
InputStream in = conn.openInputStream();
conn.close();
for(int j=0;j<12;j++)
ch=in.read();
str.append((char)ch);
par1=str.toString();
in.close();
screen4.append(par1);
display.setCurrent(screen4);still its not working.........
String uri = "file:///C:/WTK22/appdb/DefaultColorPhone/filesystem/root1/readme.txt";
FileConnection conn = (FileConnection)Connector.open( uri,Connector.READ);
InputStream in = conn.openInputStream();
conn.close();
String ss="";
String str1="";
int ch=0;
byte b[]=new byte[753];
ch=in.read(b,0,753);
str1= new String(b,0,ch);
ss=str1.substring(493,501);
screen4.append(ss);
display.setCurrent(screen4);
}catch(IOException io){} -
How to read text file by clicking on text file ?
Hello.. friends
I have made a java editor. I want to pass file name to a function in application by clicking on particular text file.
I assoiciated *.text file type with my application. when I click on text file application is run but I file is not read by my java application.
For example : in windows System all text are oppened in notepad when we click on any text file.
How to do this thing. please suggest me and if possible show me a sample code.
ThanksIf you are doing this in a web application you can set the content type appropriately and the file will open.
If you are doing this standalone you can use the Java RunTime class and execute something like this as the command "notepad.exe c:\\myfile.txt" which should open it up on a Windows operating system. -
How to read text file with big5 into db
hi,
how can i use UTL_FILE package to
read a text file with big5 characters and insert into db?
my oracle charset is AL32UTF8.
thx a lot!Thx for yr answer!!!
I have followed and it works.
However, I got another problem with HKSCS. When the text file contained HKSCS, the store procedure also treats it as Big5 and when I select it out, the character was not the orginal one.
Please suggest if you have any ideas.
Many Thanks!!! -
How to read Text file in WindowPhone 8.1
I am unable to pick text file from SD card or from mobile in windowPhone 8.1 app but image file can pick easily using FileOpenPicker.
below code working fine for image but when i changing PickerLocationId and Filter to "txt" or "doc " then not working. please do help.
FileOpenPicker
openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
openPicker.PickSingleFileAndContinue();Hi
I guess you are in wrong picker location and should have fileType also added
it should be documents lib
https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.pickers.pickerlocationid
Regards
Varun Ravindranath Please 'Mark as Answer' if my post answers your question and 'Vote as Helpful' if it helps you. -
How to read text file and store in database
Respected All,
I have text file on my computer.
I am using forms6i and oracle 9i.
I want that when i press button then specifice world in text file is read and dispaly on form to be stored in database.
Please provide some solution.
Kind RegardsHello,
Study the functions of the TEXT_IO() package
http://www.oracle.com/webapps/online-help/forms/10g/state?navSetId=_&navId=3&vtTopicFile=f1_help/oraini/c_text_io.html&vtTopicId=
Francois -
How to read text file by using jfilechooser
please check for me.. tbrowse is textfield, the file path n name are x dispaly at tBrowse. past is my class.
public void actionPerformed( ActionEvent e )
if (e.getSource() == btnBrowse)
try
FileReader in = null;
if (Chooser.showOpenDialog(past.this)== JFileChooser.APPROVE_OPTION)
File selectedFile = Chooser.getSelectedFile();
in = new FileReader(selectedFile);
tBrowse.setText(selectedFile.getPath());
catch (IOException exception)
System.out.println("Error processing file: " + exception);
Message was edited by:
fifa1509Does it compile? Does it do what you want when you run it?
If you have a problem, say what that problem is (cut and paste any
compiler error message).
One small point is that you could actually print the stack trace as this
will be much more informative if you have a problem.catch (IOException exception)
exception.printStackTrace();
} -
How to read text file flash memory
Use the 'more' command. Here is a console log showing it in use -
VG202#dir flash:
Directory of flash:/
1 -rw- 18955952 Mar 1 2002 00:19:50 +00:00 vg20x-ipvoice-mz.124-22.T.
bin
128843776 bytes total (109887488 bytes free)
VG202#copy run flash:Myconfig.txt
Destination filename [Myconfig.txt]?
1593 bytes copied in 0.392 secs (4064 bytes/sec)
VG202#dir flash:
Directory of flash:/
2 -rw- 1593 Mar 6 2002 19:28:26 +00:00 Myconfig.txt
1 -rw- 18955952 Mar 1 2002 00:19:50 +00:00 vg20x-ipvoice-mz.124-22.T.
bin
128843776 bytes total (109883392 bytes free)
VG202#
VG202#more flash:Myconfig.txt
version 12.4
no service pad
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
hostname VG202
boot-start-marker
boot-end-marker
logging message-counter syslog
enable password cisco
no aaa new-model
ip source-route
ip cef
no ipv6 cef
stcapp ccm-group 1
stcapp
stcapp feature access-code
stcapp feature speed-dial
stcapp call-control mode feature
voice-card 0
archive
log config
hidekeys
interface FastEthernet0/0
ip address 10.66.75.41 255.255.255.0
duplex auto
speed auto
interface FastEthernet0/1
no ip address
shutdown
duplex auto
speed auto
ip forward-protocol nd
ip route 0.0.0.0 0.0.0.0 10.66.75.1
no ip http server
control-plane
voice-port 0/0
timeouts initial 60
timeouts interdigit 60
timeouts ringing infinity
voice-port 0/1
ccm-manager fax protocol cisco
ccm-manager config server 10.66.90.130
ccm-manager config
ccm-manager sccp local FastEthernet0/0
ccm-manager sccp
mgcp fax t38 ecm
sccp local FastEthernet0/0
sccp ccm 10.66.75.212 identifier 2 version 6.0
sccp ccm 10.66.75.211 identifier 1 version 6.0
sccp
sccp ccm group 1
associate ccm 1 priority 1
associate ccm 2 priority 2
dial-peer voice 1 pots
service stcapp
port 0/0
dial-peer voice 10 pots
shutdown
destination-pattern 10
port 0/1
dial-peer voice 11 pots
shutdown
destination-pattern 11
port 0/0
line con 0
no modem enable
line aux 0
line vty 0 4
password cisco
login
exception data-corruption buffer truncate
end
VG202# -
How to read the whole text file lines using FTP adapter
Hi all,
How to read the whole text file lines when error occured middle of the text file reading.
after it is not reading the remaining lines . how to read the whole text file using FTP adapter
pls can you help meYes there is you need to use the uniqueMessageSeparator property. Have a look at the following link for its implementation.
http://download-west.oracle.com/docs/cd/B31017_01/integrate.1013/b28994/adptr_file.htm#CIACDAAC
cheers
James
Maybe you are looking for
-
Jconsole - remote connection thru ssh-tunnel
Hi all, I need to start jconsole on my windows-box and connect to a remote tomcat-server thru an ssh-tunnel. I have walked thru various posts and blogs, but finally couldn't get it running. On the linux-server, I have set the following JAVA_OPTS: exp
-
How can i read an image in 10g reports. I just migrated reports and forms 6 to 10g. But images are not shown in reports. Help me.... Thanks in advance...
-
BPC Input Schedule: DELETE button erase background color
Hi, Can anyone help on the following problem: I have an input schedule (either with nested rows or simple) and BPC by default marks all changed cells with red color. But when [DEL] button key is pressed in a cell all other marked cells on the same ro
-
I'm trying to develop a TrayIcon for my desktop application its working properly if i'm giving the full path of image its appearing on the system tray, but when i'm trying to give relative path of the image its not appearing on the system tray. Anybo
-
Burn tool effect still happens when painting with low opacity/flow
i posted this before, and it wasnt resolved. i figured i'd wait for an update for it to be fixed. i'm using a samsung galaxy note 10.1, and i just downloaded the 14.2 andrioid update, and the problem still occurs. please fix this issue. photoshop tou