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:
fifa1509
Does 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();
}
Similar Messages
-
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 muchBrynjar 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). -
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 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 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 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. -
Webutil- How to open text file by using Wordpad
Hello:
Is it possible to open the text file either from client or server (sun) by using the wordpad? I was able to open it with Notepad; however, it was given the rigth format such as new line.
WEBUTIL_HOST.NONBLOCKING('CMD /C NOTEPAD'||:input_select.file_name);
Thanks in advance for anyhelp.
TDThanks Phuong. I try it, but still does not work. I have tried the followings:
CLIENT_HOST('CMD/C START "editor" C:\Program Files\Windows NT\Accessories\wordpad.exe D:\temp\out.txt' );
CLIENT_HOST('CMD/C START "editor" wordpad.exe D:\temp\out.txt' );
WEBUTIL_HOST.NONBLOCKING('CMD /C C:\Program Files\Windows NT\Accessories\wordpad.exe D:\temp\out.txt');
--trang -
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 get absolute File Path using JFileChooser?
Hi,
IS there any way by which we can get the absolute file path ? e.g. If I browse thro JFileUser and Selects "a.txt" and say open, it should return me the complete file
path e.g. D:/abc/a.txt.
Present method.fileChooser.getSelectedFile().getName() return the name of the file i.e. a.txt and NOT the complete path.
Pls Help !!fileChooser.getSelectedFile().getAbsolutePath(); will do the trick.
-
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#
Maybe you are looking for
-
Ipod no longer turns on and is not recognized by computer
My ipod ran out of battery about two weeks ago. When I tried to charge it again with my wall charger, the ipod did not recognize that it was charging. No light came on or screen changed to show that it was charging. The back of the ipod felt warm but
-
Acrobat Reader 9.1 + Vist home premium 64-bit DEP crash
Hi, DEP has recently, in the past few days, started to kill Acrobat Reader 9.1 on my machine. Obviously this is a hinderance to normal life! I don't see widespread reports of this except a thread here, so that's probably not good. Any help is greatly
-
Creating new report 1st day of each month
Hello, all! I have a vi that I run to record pressure on test units. I want to create a new excel report on the 1st day of each month. If it is not the 1st day of the month I want to just add the data for each test unit as a new worksheet. I have
-
Hi Friends, Can anybody let me know how to generate the output for the Bill of Lading from SD perspective? Cheers Ivy
-
First Backup Taking 48hrs +
I received my Time Capsule in the mail on Tuesday and immediately started backing up. Its Thursday afternoon and it is only 50% complete. I feel like it shouldn't be taking this long to complete the initial backup. Any suggestions?