How to read directory and file
I am being passed a vector which has information about a file with its directory path.
I need to read the file and work on it .. how do I get to that..
Also the vector may have multiple entries and I need to go through all of them..
How do I go about this..
<code>
File file = null;
String filePath = null;
BufferedReader br = null;
String lineRead = null;
for (int i=0; i<fileV.size(); i++)
filePath = (String)fileV.get(i);
file = new File(filePath);
br = new BufferedReader(new FileReader(file));
while ((lineRead=br.readLine())!=null)
//read a line from the file
boolean b = checkPattern(lineRead);
if (b)
someOtherMethod(lineRead);
br.close();
</code>
Similar Messages
-
How to read the and Write the PDF file give me the solution
Hi all,
How to read the and Write the PDF file give me the solution
My coding is
import java.io.File;
import com.asprise.util.pdf.PDFImageWriter;
import com.asprise.util.pdf.PDFReader;
import java.io.*;
import java.io.FileOutputStream;
public class example {
// public example() {
public static void main(String a[])
try
PDFReader reader = new PDFReader(new File("C:\\AsprisePDF-DevGuide.pdf"));
reader.open(); // open the file.
int pages = reader.getNumberOfPages();
for(int i=0; i < pages; i++) {
String text = reader.extractTextFromPage(i);
System.out.println("Page " + i + ": " + text);
// perform other operations on pages.
PDFImageWriter writer = new PDFImageWriter(new FileOutputStream("c:\\new11.pdf"));
writer.open();
writer.addImage("C:\\sam.doc");
writer.close();
System.out.println("DONE.");
reader.close();
catch(Exception e){System.out.println("error:"+e);
e.printStackTrace();
I get the pdf content then it returns the string value but ther is no option to write the string to PDF, and we only add a image file to PDF,but i want to know how to wrote the string value to PDF file,
Please give response immtly
i am waiting for your reply.
thanks,
Suresh.GI have some question flow
How library to use this code.
I try runing but have not libary.
Please send me it'library
Thank you very much! -
How can I get Directory and Files from a Maped Networkdrive of the AppS
Hello,
we have the following Situation.
We have a Windows-Server (Server-A) in an Network with ActivDirectory and an Windows-Server (Server-B with an WebApplicationServer outside of these ActivDirectory as standalone.
On Server-B we mapped a Directory from Server-A (FileExplorer and then MapNetworkDrives) as Drive Q.
Now i tried to get the Directory of Q:\abcd but it doesn't work.
I tried the FM EPS_GET_DIRECTORY_LISTING and also RZL_READ_DIR, but both doesn't worked.
RZL_READ_DIR is doing a "CALL 'ALERTS' ..." and is comming back with sy-subrc = 1
EPS_GET_DIRECTORY_LISTING is doing a "CALL 'C_DIR_READ_FINISH'..." and comes back with "Wrong order of calls" in the Field file-errmsg. Next Call is "CALL 'C_DIR_READ_START'..." and this comes back with "opendir" in Field file-errmsg.
I tried the same with two Servers in the same ActivDirectory-Network. The Result was the same, i don't get the directory of the mapped drive. But now i get from the Call "CALL 'C_DIR_READ_START'..." the file-errmsg "opendir: Not a directory" and file-errno 20.
Is there any idea for solving my Problem?
I have to get this directory, read the files from the List and have to rename them after wriing the data to our databasefile.
I want to read them with OPEN DATASET, rename them by writing a new File (also OPEN DATASET) and after that i do an DELETE DATASET.
Thanks and Greetings Matthias
Edited by: Matthias Horstmann on Mar 25, 2009 4:12 PM
Filled in Scenario with 2 Servers in same AD-NetworkHalo Mattias,
i using this function get file file name and directory:
at selection-screen on value-request for p_file.
call function 'F4_FILENAME'
exporting
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_FILE'
importing
file_name = p_file.
Rgds,
Wilibrodus -
Read application server directory and file
Hi,
I'm using the FM "RZL_READ_DIR_LOCAL" to retrieve the application server directory and filename. The returned result contain all the directory name and filename. Is there any other FM can separate the result into directory and file??
Regards,
Kithi
Ya One more FM is there - Call Function Gui Upload.
It will read the file from the app server.
See this Example:-
Refer this:
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3ca6358411d1829f0000e829fbfe/frameset.htm
ABAP code for uploading a TAB delimited file into an internal table. See code below for structures.
*& Report ZUPLOADTAB * &----
*& Example of Uploading tab delimited file *
REPORT zuploadtab .
PARAMETERS: p_infile LIKE rlgrap-filename
OBLIGATORY DEFAULT '/usr/sap/'..
DATA: ld_file LIKE rlgrap-filename.
*Internal tabe to store upload data
TYPES: BEGIN OF t_record,
name1 like pa0002-VORNA,
name2 like pa0002-name2,
age type i,
END OF t_record.
DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,
wa_record TYPE t_record.
*Text version of data table
TYPES: begin of t_uploadtxt,
name1(10) type c,
name2(15) type c,
age(5) type c,
end of t_uploadtxt.
DATA: wa_uploadtxt TYPE t_uploadtxt.
*String value to data in initially.
DATA: wa_string(255) type c.
constants: con_tab TYPE x VALUE '09'.
*If you have Unicode check active in program attributes then you will
*need to declare constants as follows:
*class cl_abap_char_utilities definition load.
*constants:
con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
*START-OF-SELECTION
START-OF-SELECTION.
ld_file = p_infile.
OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
ELSE.
DO.
CLEAR: wa_string, wa_uploadtxt.
READ DATASET ld_file INTO wa_string.
IF sy-subrc NE 0.
EXIT.
ELSE.
SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1
wa_uploadtxt-name2
wa_uploadtxt-age.
MOVE-CORRESPONDING wa_uploadtxt TO wa_upload.
APPEND wa_upload TO it_record.
ENDIF.
ENDDO.
CLOSE DATASET ld_file.
ENDIF.
*END-OF-SELECTION
END-OF-SELECTION.
*!! Text data is now contained within the internal table IT_RECORD
Display report data for illustration purposes
loop at it_record into wa_record.
write:/ sy-vline,
(10) wa_record-name1, sy-vline,
(10) wa_record-name2, sy-vline,
(10) wa_record-age, sy-vline.
endloop.
reward if help. -
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 -
How to read multiple dat files.
Hello Everyone!
I am working on a project that requires one file that creates a JFrame with a current file title, JTextFields that accesses two .dat files and a JButton.
The user clicks a JButton to cycle through the first sequential .dat file. When the end of the first file is reached the file is closed, the JFrame title is changed to the second file title as the user continues to click the JButton to continue on viewing the second file?s records, until the second reaches the end of file.
The project requires using Try-Catches to catch the EOF exceptions and IOExceptions and Thread or Runnable.
I have been able to get one file to read and display its records; however, researching back through my text on how to read/write to files I haven?t been able to determine how to get to the end of the file and proceed to the next file without triggering the EOFException. I have even tried multiple Try-Catches (one for each file within the actionPerformed method) and that ends up ignoring the first file records and only displays the second files records.
This is a school project and we have only covered just the bare basics of Java over the last two months. So, any hints that anyone can provide can only be of what type of procedure will be needed or what procedure won?t help to complete the task, without giving away the solution.
I have spent approximately 40 hours of study time on this project and believe that I have definitely run into a major snag.
The following is the code I have so far:
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class StudentRead extends JFrame implements ActionListener
private JLabel gradStudentList = new JLabel("GRADUATE Student List");
private JLabel undergradStudentList = new JLabel("UNDERGRADUATE Student List");
private Font bigFont = new Font("Helvetica", Font.ITALIC, 24);
private JLabel userprompt = new JLabel("View the students");
private JTextField idNumText = new JTextField(4);
private JTextField lastNameText = new JTextField(15);
private JTextField firstNameText = new JTextField(15);
private JButton viewRecordButton = new JButton("View Record");
private JLabel idNumberLabel = new JLabel("ID Number");
private JLabel lastNameLabel = new JLabel("Last name");
private JLabel firstNameLabel = new JLabel("First name");
private Container con = getContentPane();
DataInputStream gradStudentInStream;
DataInputStream undergradStudentInStream;
public StudentRead()
super("Read Student Records");
try
gradStudentInStream = new DataInputStream(new FileInputStream("GradStudents.dat"));
undergradStudentInStream = new DataInputStream(new FileInputStream("UndergradStudents.dat"));
catch(IOException e)
System.err.println("File not opened");
System.exit(1);
setSize(325, 200);
con.setLayout(new FlowLayout());
gradStudentList.setFont(bigFont);
con.add(gradStudentList);
con.add(userprompt);
con.add(idNumberLabel);
con.add(idNumText);
con.add(lastNameLabel);
con.add(lastNameText);
con.add(firstNameLabel);
con.add(firstNameText);
con.add(viewRecordButton);
viewRecordButton.addActionListener(this);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
public void actionPerformed(ActionEvent e1)
String lastName, firstName;
int IdNum;
try
IdNum = gradStudentInStream.readInt();
lastName = gradStudentInStream.readUTF();
firstName = gradStudentInStream.readUTF();
idNumText.setText(String.valueOf(IdNum));
lastNameText.setText(lastName);
firstNameText.setText(firstName);
catch(EOFException e2)
closeFile();
System.exit(0);
catch(IOException e3)
System.err.println("Error reading file");
System.out.println("out");
System.exit(1);
public void closeFile()
try
gradStudentInStream.close();
System.exit(0);
catch(IOException e)
System.err.println("Error closing file");
System.exit(1);
public static void main(String[] args)
StudentRead rsr = new StudentRead();
}deepak_1your.com wrote:
hi,
If you want to read a file guarding yourself agianst exceptions....
check this article.... the code presented in this article might suit your needs...
[http://1your.com/fusion/infusions/articles/readarticle.php?article_id=17|http://1your.com/fusion/infusions/articles/readarticle.php?article_id=17]
And how does that help with a DataInputStream? -
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. -
How to read an excel file in webdynpro application
Hello Experts,
Can someone please tell me how to read an excel file in a webdynpro application?
There is a tutorial for how to write contect into an excel, but i want to read the excel.
Can someone help please !!
Thanks and Kind regards,
G.Singh.Hello Experts,
I have done all the given above.
I want to read a excel file from KM. My code is as below
ResourceContext resourceContext = buildResourceContext();
IResourceFactory resourceFactory = ResourceFactory.getInstance();
RID pathRID = RID.getRID("/documents/ExcelReport.xls");
IResource resource = resourceFactory.getResource(pathRID, resourceContext);
Workbook wb = Workbook.getWorkbook(resource.getURI().getPath());
Sheet sh = wb.getSheet(0);
int columns = sh.getColumns();
int rows = sh.getRows();
wdComponentAPI.getMessageManager().reportSuccess(" Rows: " + rows);
wdComponentAPI.getMessageManager().reportSuccess(" Columns: " + columns);
This does not give me the excel file form the KM
Can you please just what i can do at this point?
Kind Regards,
G Singh. -
How to read the properties file available in Server File structure in webdy
hi all,
I have developed one webdynpro application. In this application i need to access mdm server to continue. For getting the connection i need to pass the IP addresses.
Can i have code how to read the properties file which is residing in the server file. with out included along with the application. keeping some where in the file structure in the server. I want to read that properties file by maintain the iP addresses and users in properties file based on the key i want to read like below.
servername="abcServer"
username="john"
password="test123"
Please send me the code how to read this properties file from the file structure and how to read this values by key in webdynpro application
Regards
VijayHi Vijay,
You can try this piece of code too:
Properties props = new Properties();
//try retrieve data from file
//catch exception in case properties file does not exist
try {
props.load(new FileInputStream("c:\property\Test.properties")); //File location
String serverName = props.getProperty("servername"); //Similarly, you can access the other properties
if(serverName==null)
//....do appropriate handling
} catch(IOException e)
e.printStackTrace();
Regards,
Alka. -
How to read a trace file?
Can someone point me to a good resource where I can learn how to read a trace file? I have read somewhere that TKPROF can leave some things unattended. Worse, it reports things incorrectly.
I usually recommend use Trace Analyzer (TRCA), Note:224270.1
It includes all the details found on TKPROF, plus additional information normally requested and used for a transaction performance analysis. Generated report is more readable and extensive than text format used on prior version of this tool and on current TKPROF. -
How to read an ARPA file in java
Hi
Im new in java and dont know many thing about it, I want to know how can read an ARPA file in java.
pleas describ it step bye step and esy to understand.
Edited by: 836719 on Feb 14, 2011 8:15 PM836719 wrote:
ok i explain what i want to do maybe u can help me more,
i want to read an arpa file and search it to find for example a word.so u think which method that u mentioned above is beter???
It will be pleasure if u have any tip that can help me.1. Learn the basics of programming as well as how to logically construct and deconstruct a problem domain.
2. Learn the basics of programming java.
3. Learn about java.io.*
4. Learn about java swing
5. Find documentation that describes the format of the ARPA file.
6. Read the documentation and understand it.
7. Find a source for ARPA files (if this is online then there is more java to learn as well.)
8. Use 1,2 and 3 to write java code that consumes the ARPA file.
9. Use 4 to ask the user for a word.
10. Use 1 and 2 to write code that 'searches' what you read in 8. -
How to read from properties file
Hi,
I am using JSR 168.
while creating a new portlet, a folder gets created with the name as "portlet". Under which is resource package and <PortletName>Bundle.java.
pls tell me how to read from .properties file.
waiting eagerly for some reply
Thanks & Regards,
HP
Edited by: user9003827 on Apr 13, 2010 3:42 AMI think i have mixed it up :)
I have looked at it again and believe you are using regular JSP portlets.
Can you tell what you want to achieve by reading .properties file. Are you meaning the preferences of the portlet or what exactly are you trying to do?
Reading propertie files is easy:
// Read properties file.
Properties properties = new Properties();
try {
properties.load(new FileInputStream("filename.properties"));
String myKey = properties.getProperty("yourKey");
} catch (IOException e) {
}Edited by: Yannick.O on 13-Apr-2010 05:52 -
How to read the backup file of my own iphone...
how to read the backup file of my own iphone... becase I'm running out of space in my iphone so need to delete some photos. I wanna know do i have to copy photos to my computer or is it available in the back up file ????
Always move (copy and delete) your photos from Camera Roll to your computer.
Camera Roll is the digital camera card. -
How to read an xml file from headers
Hi ,
I am not getting how to read an xml file sent by client device in header to server.
Thankx.There is a getHeader() in HttpServletRequest interface
String locationURL=request.getHeader("Location");If URL of your file was set in Location attribute of header.
Edited by: ngpgeeta on Dec 19, 2008 8:03 AM -
How to read each and every word from a string.
Hi all,
I have a string which is having many label numbers. if the string is lv_str, its value is like, 11111111111111##22222222222222##3333333333333.
I need to move the values alone into internal table. each value should be updated as a single row into one internal table. How to read each and every word of the string and move to an internal table.
the internal table should be like this.
11111111111111
22222222222222
3333333333333
Can any one give me a suggestion in this regard.
POINTS PROMISED.
Regards,
BuvanaHi,
If you know the format and length of the data
Use split at '#' so that you will get the individual values.
Thean append it to internal table.
Reward iof helpful.
Maybe you are looking for
-
Dublicate Value In HTML PL/SQL Report
hi, i have to enter item name and item Price iinto transaction_details by using a form and labour Work, labour amount into LAB_WORK_DTL table using a form . Now Problem is when i fetch these value in to PL/SQL Report then it's shows me double value l
-
The feature you are trying to use is on a network resource that is not available
I am trying to download and install the latest release of iTunes but I keep getting an error message - The feature you are trying to use is on a network resource that is unavailable. Click OK to try again, or enter a alternate path to a folder contai
-
Without tax is there any problem post billing document into FI
Hi All, in my project we are not going determined any tax in sales order condition type. we are just maintaining the pricing condition. is there any problem with out tax maintain to post billing document into account document. Thanks, KR Edited by: k
-
Hierarchical keywords, collections and XMP
Hi,<br /><br />I tried to figure out how LR stores the hierarchical keyword tree in the XMP data. XMP data written by LR contains all the info to recreate the keyword hierarchy. While the keyword text strings are plain ascii, the keyword linking info
-
Rounding off to two decimal places
Hello, For simplicity, is there a method which will round off a double variable to two decimal places. Excample: if I have a result which equals 2.1999998 and I want to display this as 2.20 in a TexTField. Any help would be much appreciated. Thanks