Help finding key characters in txt file
Hey I have just been trying to code a script that I can use to search through a bunch of rankings (like 1.Jorden 2.Honza 3.Bill 4.Ted etc) and find how many times each player recieved a vote for each ranking.
So I might end up with, Jorden was voted 1st 9 times, 2nd 3 times and 3rd 0 times.
The votes are in a text document, here is the script so far:
public static void printVotes() {
int count = 0;
int a = 0;
File nFile = new File("Sick1.txt");
FileReader inStr = new FileReader(nFile);
BufferedReader inBuff = new BufferedReader(inStr);
for(int i = 1; i < 15; i++) {
while(a == 0) {
String txtName = inBuff.readLine();
if(txtName != null) { //txtName holes the line IE if its like this 1.) Honza
StringTokenizer placing = new StringTokenizer(txtName, i);
StringTokenizer name = new StringTokenizer(txtName, "Honza");
if(placing != null && name != null) {
count++;
} else {
System.out.println(count);
a = 1;
Now it is far from perfect (that being the main reason it does'nt work) but my key question is:
what is the best way to check how many lines in the .txt document contain the int i (from the for loop) and a givin name (eg "Honza")?
Your logic needs to look like this:
for (each line)
split the line into the rank and name;
Increment the count for the name/rank pair.
}I would use a Map to store the rank counts for each name found.
Similar Messages
-
Find Hidden Characters-in downloaded file
All,
I have a file interface that downloading file to SANS server using open dataset. But recently we are getting some hidden characters in the file. These are getting from a long text.
Now my requirement is to find these hidden characters and display in the screen and user can correct then go for download.
Currently i am using Notepad++ or using this link for finding the hidden characters
http://string.online-toolz.com/tools/string-functions.php
Now user wanted to use the same functionality with in SAP using ABAP.
Any input on this appreciated.
a®Similar functionality can be achieved by JavaScript. You can pass the entire Text and create your function in JS to find out the Hidden Characters. If you are successful finding the JS which can do this job for you, you can use [JS Engine|http://help.sap.com/saphelp_nw04/helpdata/en/49/a8e3c8d59811d4b2e90050dadfb92b/frameset.htm] available in ABAP.
Refer to [ABAP & JavaScript|http://help-abap.zevolving.com/2011/10/javascript-in-abap/] to see the simple JS usage.
Regards,
Naimesh Patel -
Help. Does use of .txt file make sense or code directly into an ArrayList
I am writing my first program and I want to put a series of information in various .txt files. This is because I will have a lot of different objects that I will create that will needed to be iterated over (most of the objects are similar in many ways). It seemed to me that a .txt file would be better than writing the items directly in an arraylist (if you know what i mean). What do you think?
There will be 7 different objects that will be iterated over (and there will be 12 other objects doing other things as well, they will not be in .txt format), and I thought instead of having to maintain it through the actual code, I would just have .txt files that I create in notepad or something so that when I need to make changes to one of the 7 objects I only have to get the .txt file instead of having to wade through the code to find that object.
Does this make sense?
It seems that I will now have to do a lot of I / O to make it work, so now I am thinking maybe it is better to simply use the arrylist. Is there a benefit of one over the other in this circumstance?
Also one of the objects has jpeg files that will need to be iterated over. Actually for these I will put them in an array list, because I can't seem to figure out yet how to get an image and the information about the image to display within I/O (like CD covers and their titles).
Thank you for any help and suggestions I feel a little overwhelmed, but hopeful, with you kind folks.
Peace
NB I know that I am not using the correct terminology, but I hope that you can understand what I mean.
Message was edited by:
peacerosetxI am writing my first program and I want to put a
series of information in various .txt files. Thisis
because I will have a lot of different objects thatI
will create that will needed to be iterated over
(most of the objects are similar in many ways). It
seemed to me that a .txt file would be better than
writing the items directly in an arraylist (if you
know what i mean). What do you think? I think I do not know what you mean. I also think
that ArrayLists and files shouldn't replace eachI am going to use an ArrayList. Merci
other.
There will be 7 different objects that will be
iterated over (and there will be 12 other objects
doing other things as well, they will not be in.txt
format),Seven objects? Twelve objects? Huh? Why not use
arrays? And how do you get an object into a text
file?
and I thought instead of having to maintain
it through the actual code, I would just have .txt
files that I create in notepad or something sothat
when I need to make changes to one of the 7 objectsI
only have to get the .txt file instead of havingto
wade through the code to find that object.
Does this make sense? Your description? Not to me.
It seems that I will now have to do a lot of I / Oto
make it work, so now I am thinking maybe it isbetter
to simply use the arrylist. Is there a benefit of
one over the other in this circumstance? Uh, ArrayList is way faster and much easier
modifyable.
Also one of the objects has jpeg files that willneed
to be iterated over. Actually for these I will put
them in an array list, because I can't seem tofigure
out yet how to get an image and the informationabout
the image to display within I/O (like CD coversand
their titles). "Display within I/O"? This makes no sense.
NB I know that I am not using the correct
terminology, but I hope that you can understandwhat
I mean.If you're not using the correct terminology, there's
no chance for us to understand you. If you say
"objects" but mean "classes", then say classes. -
Remove control characters in txt file (saved from Excel)
Hi,
I have a txt file that contains invisible control characters and I want to remove those characters. I've been thinking of 2 options
1/ Get the content of the file into a string, then go through each character and basically takes only alphanumeric, new lines, Alt+Enter character (character that is created in txt files in Excel that breaks line). With this approach, I'm stuck on getting the character code for Alt+Enter so if anyone could point out. That helps a great deal.
2/ Use some pattern matching {ctrnl} or something to remove all control characters. I've tried this approach and it didn't work for me.
Please help me with this problem. Any help or suggestion is greatly appreciated.(saved from Excel) Why not save it as csv?
trivektor wrote:
With this approach, I'm stuck on getting the character code for Alt+Enter so if anyone could point out. That helps a great deal.
You can figure that out with a hex editor or just write a small app that prints int values for each byte, not character, and print the file.
Presumably you already found the Character class and its methods.
Edited by: jschell on Sep 22, 2008 4:29 PM -
Finding words in a txt file!
Hi guys,
I have to write a program that opens a .txt file and looks for a specific word in the file and then prints out the entire line that word appears in. I have to use a String Tokenizer? I don't know how to write the program. All I have so far is a program that prints the entire txt document (or each line). I think String Tokenizer is involved in here somewhere but I don't know how to use it.
import java.io.FileReader;
import java.util.StringTokenizer;
import java.io.*;
public class Find
public static void main (String[] args) throws IOException
String line;
String name;
String file="find.txt";
StringTokenizer tokenizer;
FileReader x = new FileReader (file);
BufferedReader inFile = new BufferedReader (x);
line = inFile.readLine();
while (line != null)
tokenizer = new StringTokenizer (line);
word = tokenizer.nextToken("word");
System.out.println (line + "\n");
line = inFile.readLine();
inFile.close();
The text file Find.txt just has a few lines of text in it.
I want to make it so that I can look for a specific word in the text file and the resulting printout will be the entire line that the word appears in.
Any help would be great! Thanks!Your first post is very close to what you want:
import java.io.FileReader;
import java.util.StringTokenizer;
import java.io.*;
public class Find
public static void main (String[] args) throws IOException
String line;
String name;
String file="find.txt";
StringTokenizer tokenizer;
FileReader x = new FileReader (file);
BufferedReader inFile = new BufferedReader (x);
line = inFile.readLine();
while (line != null)
tokenizer = new StringTokenizer (line);
String word = tokenizer.nextToken();
if (word.equals("word")) // we are searchig for the String word
System.out.println ("found it! "+line + "\n");
line = inFile.readLine();
inFile.close();
[\code] -
Help in reading a csv txt file!
hey i have a problem with this code, Im trying to read a txt file, containing users and scores, and list scores separate, but I get the fist 3 scores empty(0) can any one help plz?
String uname;
int theScore;
int noScores = 0;
int [] scores;
public highScores()
try
FileReader gamers = new FileReader( "Gamers.txt" );
BufferedReader br = new BufferedReader( gamers );
String stringRead = br.readLine( );
while( stringRead != null )
StringTokenizer st = new
StringTokenizer( stringRead, "," );
String uname = st.nextToken( );
theScore = Integer.parseInt( st.nextToken( ) );
noScores = noScores + 1;
scores = new int[noScores];
for(int i = (noScores - 1);i < noScores;i++)
scores[i] = theScore;
System.out.println("" + uname + "," + theScore);
stringRead = br.readLine( );
br.close( );
for(int i = 0;i < noScores;i++)
System.out.println("" + scores);
catch( IOException ioe )
ioe.printStackTrace( );
//file im reading from (Gamers.txt)
Usename,1234
Me,678
you,456
them,698
//output
Usename,1234
Me,678
you,456
them,698
0
0
0
698
Press any key to continue . . .Why are you creating the score array inside he while loop? What's that for? It looks like it's for all the scores, but if you have 3 lines, then you're creating 3 different scores arrays--one with 1 element, 1 with 2 elements, and 1 with 3 elements.
For all but the last one, you're creating it, populating the last element, then throwing it away.
For the last one, you create it, populate the last element (leaving the first three with their default value of 0) and then that's what gets printed.
When you have this kind of problem, print out a bunch of relevant stuff (and even some stuff that you think is not relevant) at each step of the way, so ou can see what your code is doing. Yout THINK you know what it's doing, but obviously you're mistaken. If you can't figure it out from staring at it, then you'll have to let the code itself tell you what's really going on.
You'll have to create the array before you start the while loop, which means you'll have to know ahead of time how many scores you have, or know some maximum that you could possibly have and make it big enough to hold that many.
Or,instead of an array, you couse use a List, such as java.util.ArrayList.
http://java.sun.com/docs/books/tutorial/collections/ -
Separeted enter key / new line Txt File
Hi Experts;
I want to send mail with attach file (xxx.txt).
xxx.txt file's source itab.
I'm seeing xxx.txt file at mail.. But It's not separeted enter key / new line.
I'want to see line-by-line my itab at the xxx.txt file.
How can I make?
Best regards.Hi, Melih.
Try to insert new lines using cl_abap_char_utilities=>newline.
Like this:
DATA:
BEGIN OF gs_tab,
string TYPE string,
END OF gs_tab,
gt_tab LIKE TABLE OF gs_tab WITH HEADER LINE.
gt_tab-string = 'first row'.
APPEND gt_tab.
CONCATENATE 'second row' cl_abap_char_utilities=>newline INTO gt_tab-string.
APPEND gt_tab.
gt_tab-string = 'third row'.
APPEND gt_tab.
Best regards,
George Shlyahov. -
[regex help]Find EXACT characters in a String.
Ok, i got this so far ...
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Testing2 {
public static void main(String[] args) {
Pattern p = Pattern.compile("[wati]");
String text = "water";
Matcher m = p.matcher(text);
if (m.find()) {
System.out.print("Found !");
}With that code i got a match, but i ONLY want to find a match if the String matches the EXACTS characters in the Pattern ...
in this case i got, 'w' 'a' 't' 'i', 'w' 'a' 't', are in water, but 'i' NOT, so i don't want to have a match !
i don't know how to acomplish this :(
hope you can help me, thanks in advance :DUsername7260 wrote:
Ok, i got this so far ...
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Testing2 {
public static void main(String[] args) {
Pattern p = Pattern.compile("[wati]");
String text = "water";
Matcher m = p.matcher(text);
if (m.find()) {
System.out.print("Found !");
}With that code i got a match, but i ONLY want to find a match if the String matches the EXACTS characters in the Pattern ...
in this case i got, 'w' 'a' 't' 'i', 'w' 'a' 't', are in water, but 'i' NOT, so i don't want to have a match !
i don't know how to acomplish this :(AFAIK there's no syntax in regular expressions to accomplish this. Try turning your string into a character array, sorting it, and then do a simple comparison. -
I need help for reading from a .txt file.
My goal in this program is to display the data from the text file to the command prompt. Everything compiles, but its doesnt display the data.
It probably has to do with my constructer. So help with revising the constructing would be appreciated. I am new to programming by the way.
import java.util.*;
import java.io.*;
class Inventory
public static void main(String[] args)
final int MAX = 50;
InventoryItem[] items = new InventoryItem[MAX];
StringTokenizer tokenizer;
String line;
String name;
String file = " inventory.txt ";
int units = 0;
int count = 0;
float price;
try
FileReader fr = new FileReader ("inventory.txt");
BufferedReader inFile = new BufferedReader(fr);
line = inFile.readLine();
while (line !=null)
tokenizer = new StringTokenizer (line);
name = tokenizer.nextToken();
try
units = Integer.parseInt(tokenizer.nextToken());
price = Float.parseFloat(tokenizer.nextToken());
items[count++] = new InventoryItem(name, units, price);
catch (NumberFormatException exception)
System.out.println("error in input.Line ignored:");
System.out.println(line);
line = inFile.readLine();
inFile.close();
for (int i = 0; i<count; i++)
System.out.println (items);
catch (IOException exception)
System.out.println("The file " + file + "was not found.");
} //end of main method
}// end of Inventory class
public class InventoryItem
private String name;
private int units;
private float price;
public InventoryItem (String nameOfItem, int numOfUnits, float priceOfItem)
name = nameOfItem;
units = numOfUnits;
price = priceOfItem;Use CODE tags
What's not printing?
try
units =
its = Integer.parseInt(tokenizer.nextToken());
price =
ice = Float.parseFloat(tokenizer.nextToken());
items[count++] = new InventoryItem(name, units,
nits, price);
catch (NumberFormatException exception)
System.out.println("error in input.Line <========= THIS ???????
.Line ignored:");
System.out.println(line); <============= AND THIS???
line = inFile.readLine();
inFile.close();
for (int i = 0; i<count; i++)
System.out.println (items); <========== THIS IS OK, right?
If I have correctly indentified your problem, then the reason it's not printing is that your print statements are within a catch block, and evidently your code is not throwing any NumberFormatExceptions -
(Urgent help needed) how to read txt file and store the data into 2D-array?
Hi, I have a GUI which allow to choose file from the file chooser, and when "Read file" button is pressed, I want to show the array data into the textarea.
The sample data is like this followed:
-0.0007 -0.0061 0.0006
-0.0002 0.0203 0.0066
0 0.2317 0.008
0.0017 0.5957 0.0008
0.0024 1.071 0.0029
0.0439 1.4873 -0.0003
I want my program to scan through and store these data into 2D array.
However for some reason, my source code issues errors, and I don't know what's wrong with it, seems to have a problem in StringTokenizer though. Can anybody help me?
Thanks in advance.
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.StringTokenizer;
public class FileReduction1 extends JFrame implements ActionListener{
// GUI features
private BufferedReader fileInput;
private JTextArea textArea;
private JButton openButton, readButton,processButton,saveButton;
private JTextField textfield;
private JPanel pnlfile;
private JPanel buttonpnl;
private JPanel buttonbar;
// Other fields
private File fileName;
private String[][] data;
private int numLines;
public FileReduction1(String s) {
super(s);
// Content pane
Container cp = getContentPane();
cp.setLayout(new BorderLayout());
// Open button Panel
pnlfile=new JPanel(new BorderLayout());
textfield=new JTextField();
openButton = new JButton("Open File");
openButton.addActionListener(this);
pnlfile.add(openButton,BorderLayout.WEST);
pnlfile.add(textfield,BorderLayout.CENTER);
readButton = new JButton("Read File");
readButton.addActionListener(this);
readButton.setEnabled(false);
pnlfile.add(readButton,BorderLayout.EAST);
cp.add(pnlfile, BorderLayout.NORTH);
// Text area
textArea = new JTextArea(10, 100);
cp.add(new JScrollPane(textArea),BorderLayout.CENTER);
processButton = new JButton("Process");
//processButton.addActionListener(this);
saveButton=new JButton("Save into");
//saveButton.addActionListener(this);
buttonbar=new JPanel(new FlowLayout(FlowLayout.RIGHT));
buttonpnl=new JPanel(new GridLayout(1,0));
buttonpnl.add(processButton);
buttonpnl.add(saveButton);
buttonbar.add(buttonpnl);
cp.add(buttonbar,BorderLayout.SOUTH);
/* ACTION PERFORMED */
public void actionPerformed(ActionEvent event) {
if (event.getActionCommand().equals("Open File")) getFileName();
if (event.getActionCommand().equals("Read File")) readFile();
/* OPEN THE FILE */
private void getFileName() {
// Display file dialog so user can select file to open
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showOpenDialog(this);
// If cancel button selected return
if (result == JFileChooser.CANCEL_OPTION) return;
if (result == JFileChooser.APPROVE_OPTION)
fileName = fileChooser.getSelectedFile();
textfield.setText(fileName.getName());
if (checkFileName()) {
openButton.setEnabled(false);
readButton.setEnabled(true);
// Obtain selected file
/* READ FILE */
private void readFile() {
// Disable read button
readButton.setEnabled(false);
// Dimension data structure
getNumberOfLines();
data = new String[numLines][];
// Read file
readTheFile();
// Output to text area
textArea.setText(data[0][0] + "\n");
for(int index=0;index < data.length;index++)
for(int j=1;j<data[index].length;j++)
textArea.append(data[index][j] + "\n");
// Rnable open button
openButton.setEnabled(true);
/* GET NUMBER OF LINES */
/* Get number of lines in file and prepare data structure. */
private void getNumberOfLines() {
int counter = 0;
// Open the file
openFile();
// Loop through file incrementing counter
try {
String line = fileInput.readLine();
while (line != null) {
counter++;
System.out.println("(" + counter + ") " + line);
line = fileInput.readLine();
numLines = counter;
closeFile();
catch(IOException ioException) {
JOptionPane.showMessageDialog(this,"Error reading File",
"Error 5: ",JOptionPane.ERROR_MESSAGE);
closeFile();
System.exit(1);
/* READ FILE */
private void readTheFile() {
// Open the file
int row=0;
int col=0;
openFile();
System.out.println("Read the file");
// Loop through file incrementing counter
try {
String line = fileInput.readLine();
while (line != null)
StringTokenizer st=new StringTokenizer(line);
while(st.hasMoreTokens())
data[row][col]=st.nextToken();
System.out.println(data[row][col]);
col++;
row++;
closeFile();
catch(IOException ioException) {
JOptionPane.showMessageDialog(this,"Error reading File",
"Error 5: ",JOptionPane.ERROR_MESSAGE);
closeFile();
System.exit(1);
/* CHECK FILE NAME */
/* Return flase if selected file is a directory, access is denied or is
not a file name. */
private boolean checkFileName() {
if (fileName.exists()) {
if (fileName.canRead()) {
if (fileName.isFile()) return(true);
else JOptionPane.showMessageDialog(null,
"ERROR 3: File is a directory");
else JOptionPane.showMessageDialog(null,
"ERROR 2: Access denied");
else JOptionPane.showMessageDialog(null,
"ERROR 1: No such file!");
// Return
return(false);
/* FILE HANDLING UTILITIES */
/* OPEN FILE */
private void openFile() {
try {
// Open file
FileReader file = new FileReader(fileName);
fileInput = new BufferedReader(file);
catch(IOException ioException) {
JOptionPane.showMessageDialog(this,"Error Opening File",
"Error 4: ",JOptionPane.ERROR_MESSAGE);
System.out.println("File opened");
/* CLOSE FILE */
private void closeFile() {
if (fileInput != null) {
try {
fileInput.close();
catch (IOException ioException) {
JOptionPane.showMessageDialog(this,"Error Opening File",
"Error 4: ",JOptionPane.ERROR_MESSAGE);
System.out.println("File closed");
/* MAIN METHOD */
/* MAIN METHOD */
public static void main(String[] args) throws IOException {
// Create instance of class FileChooser
FileReduction1 newFile = new FileReduction1("File Reduction Program");
// Make window vissible
newFile.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
newFile.setSize(500,400);
newFile.setVisible(true);
Java.lang.NullpointException
at FileReductoin1.readTheFile <FileReduction1.java :172>
at FileReductoin1.readFile <FileReduction1.java :110>
at FileReductoin1.actionPerformed <FileReduction1.java :71>
.1) Next time use the CODE tags. this is way too much unreadable crap.
2) The problem is your String[][] data.... the only place I see you do anything approching initializing it is
data = new String[numLines][];I think you want to do this..
data = new String[numLines][3];anyway that's why it's blowing up on the line
data[row][col]=st.nextToken(); -
AppleScript puts control characters in txt file, inflating it enormously
Hi all,
I've come across a strange problem. I have an AppleScript file that puts up a dialog box at regular intervals asking me to write down what I am doing (to create an activity log). The file is saved to my Documents folder. This has been working just fine for several months (years), and now, all of a sudden, AppleScript fails on me. The reason is, the log file is inflated out of proportions because it contains hidden control characters (gremlins) between each letter and zillions of them between words and lines. Opening one of these files makes TextEdit go crazy ('Application not responding'). I discovered these gremlins when I opened the document in Classic mode with Word 5 (the best application ever to have been produced by MS, which allows me to remove them and make the file palatable to TextEdit again).
But that doesn't solve the problem: Every entry continues to be inserted with another load of gremlins, and I can't understand why. I deleted preferences both for TextEdit and AppleScript, and I performed regular disk maintenance.
TextEdit is set to save plain text files, end-of-line is Macintosh style, character set is Western Mac OS Roman. It's always been like this before when it worked ok.
Any ideas?
Thanks in advance.
G4 MDD 1.25 GHz, 768 MB RAM Mac OS X (10.3.9)The solution to my problem can be found in the AppleScript forum here:
http://discussions.apple.com/message.jspa?messageID=2353871
With many thanks to reese_, who provided the solution, and to Tom, who directed me there! -
Need help finding key on keyboard
My Wifi's password contain's an acute key, but I can't find it on the iPhone. (It's the button next to the one, for those that don't know).
There is no acute-sorry. For tilde, tap the .?123 button. Then tap the button that is one button above it, which reads #+= Go up one and over three -- that's tilde, but no acute button.
-
Help with .txt files importing / showing
I am working cs4. / as 3.0
I need some help understanding placing text with .txt files.
I have a txt & css file in my site folder.
Do I need to add a line to my script to locate the files in
my site folder?
Any help would be appreciated. thanks
Here is what I have so far.
var fileTxt:String;
var myTextLoader:URLLoader = new URLLoader();
var cssLoader:URLLoader = new URLLoader();
myTextLoader.addEventListener(Event.COMPLETE, onloaded);
myTextLoader.load(new URLRequest("textInfo.txt"));
function onLoaded(e:Event):void {
fileTxt=myTextLoader.data;
callCss();
function callCss():void {
var cssRequest:URLRequest=new URLRequest("stylesSite.css");
cssLoader.addEventListener(Event.COMPLETE, onCss);
cssLoader.load(cssRequest);
function onCss(e:Event):void {
var css:StyleSheet = new StyleSheet();
css.parseCSS(cssLoader.data);
infoText.styleSheet=css;
infoText.wordWrap=true;
infoText.htmlText=fileTxt;
infoScroll.update();Thanks for the information. Am I missing something or you forgot to actually post a question?
What are the problems you have? What have you tried and how did not it work?
Mike -
Send email with txt file as attachment
Hi ,
can any one help me in download as txt file using the function module SO_OBJECT_SEND along with email .
a sample code using this function module would be helpfull.
Thanks,
vinay .Hi vinay,
Not only TXT file, u can send any
other file like word,excel,pdf,exe, etc.
1. There is some trick involved
in the binary files.
2. I have made a program (and it works fantastic)
ONLY 6 LINES FOR EMAILING
BELIEVE ME
ITS A FANTASTIC PROGRAM.
IT WILL WORK LIKE OUTLOOK EXPRESS !
3. The user is provided with
a) file name
b) email address to send mail
and it sends ANY FILE (.xls,.pdf .xyz..)
Instantaneously !
4. Make two things first :
1. Include with the name : ZAMI_INCLFOR_MAIL
2. Report with the name : ZAM_TEMP147 (any name will do)
3. Activate both and execute (2)
4. After providing filename, email adress
5. Code for Include :
10.08.2005 Amit M - Created
Include For Mail (First Req F16)
Modification Log
Data
DATA: docdata LIKE sodocchgi1,
objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,
objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objhex LIKE solix OCCURS 10 WITH HEADER LINE,
reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
DATA: tab_lines TYPE i,
doc_size TYPE i,
att_type LIKE soodk-objtp.
DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.
FORM
FORM ml_customize USING objname objdesc.
Clear Variables
CLEAR docdata.
REFRESH objpack.
CLEAR objpack.
REFRESH objhead.
REFRESH objtxt.
CLEAR objtxt.
REFRESH objbin.
CLEAR objbin.
REFRESH objhex.
CLEAR objhex.
REFRESH reclist.
CLEAR reclist.
REFRESH listobject.
CLEAR listobject.
CLEAR tab_lines.
CLEAR doc_size.
CLEAR att_type.
Set Variables
docdata-obj_name = objname.
docdata-obj_descr = objdesc.
ENDFORM. "ml_customize
FORM
FORM ml_addrecp USING preceiver prec_type.
CLEAR reclist.
reclist-receiver = preceiver.
reclist-rec_type = prec_type.
APPEND reclist.
ENDFORM. "ml_customize
FORM
FORM ml_addtxt USING ptxt.
CLEAR objtxt.
objtxt = ptxt.
APPEND objtxt.
ENDFORM. "ml_customize
FORM
FORM ml_prepare USING bypassmemory whatatt_type whatname.
IF bypassmemory = ''.
Fetch List From Memory
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = listobject
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID '61' TYPE 'E' NUMBER '731'
WITH 'LIST_FROM_MEMORY'.
ENDIF.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
COMPRESSED_SIZE =
TABLES
in = listobject
out = objbin
EXCEPTIONS
OTHERS = 1
IF sy-subrc <> 0.
MESSAGE ID '61' TYPE 'E' NUMBER '731'
WITH 'TABLE_COMPRESS'.
ENDIF.
ENDIF.
Header Data
Already Done Thru FM
Main Text
Already Done Thru FM
Packing Info For Text Data
DESCRIBE TABLE objtxt LINES tab_lines.
READ TABLE objtxt INDEX tab_lines.
docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
CLEAR objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'TXT'.
APPEND objpack.
Packing Info Attachment
att_type = whatatt_type..
DESCRIBE TABLE objbin LINES tab_lines.
READ TABLE objbin INDEX tab_lines.
objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = att_type.
objpack-obj_name = 'ATTACHMENT'.
objpack-obj_descr = whatname.
APPEND objpack.
Receiver List
Already done thru fm
ENDFORM. "ml_prepare
FORM
FORM ml_dosend.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = docdata
put_in_outbox = 'X'
commit_work = 'X' "used from rel. 6.10
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
TABLES
packing_list = objpack
object_header = objhead
contents_bin = objbin
contents_txt = objtxt
CONTENTS_HEX = objhex
OBJECT_PARA =
object_parb =
receivers = reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8
IF sy-subrc <> 0.
MESSAGE ID 'SO' TYPE 'S' NUMBER '023'
WITH docdata-obj_name.
ENDIF.
ENDFORM. "ml_customize
FORM
FORM ml_spooltopdf USING whatspoolid.
DATA : pdf LIKE tline OCCURS 0 WITH HEADER LINE.
Call Function
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = whatspoolid
TABLES
pdf = pdf
EXCEPTIONS
err_no_otf_spooljob = 1
OTHERS = 12.
Convert
PERFORM doconv TABLES pdf objbin.
ENDFORM. "ml_spooltopdf
FORM
FORM doconv TABLES
mypdf STRUCTURE tline
outbin STRUCTURE solisti1.
Data
DATA : pos TYPE i.
DATA : len TYPE i.
Loop And Put Data
LOOP AT mypdf.
pos = 255 - len.
IF pos > 134. "length of pdf_table
pos = 134.
ENDIF.
outbin+len = mypdf(pos).
len = len + pos.
IF len = 255. "length of out (contents_bin)
APPEND outbin.
CLEAR: outbin, len.
IF pos < 134.
outbin = mypdf+pos.
len = 134 - pos.
ENDIF.
ENDIF.
ENDLOOP.
IF len > 0.
APPEND outbin.
ENDIF.
ENDFORM. "doconv
CODE FOR PROGRAM
5.
REPORT zam_temp147 .
INCLUDE zami_inclfor_mail.
DATA
DATA : itab LIKE tline OCCURS 0 WITH HEADER LINE.
DATA : file_name TYPE string.
data : path like PCFILE-PATH.
data : extension(5) type c.
data : name(100) type c.
SELECTION SCREEN
PARAMETERS : receiver TYPE somlreci1-receiver lower case.
PARAMETERS : p_file LIKE rlgrap-filename
OBLIGATORY.
AT SELECTION SCREEN
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CLEAR p_file.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = p_file.
START-OF-SELECTION
START-OF-SELECTION.
PERFORM ml_customize USING 'Tst' 'Testing'.
PERFORM ml_addrecp USING receiver 'U'.
PERFORM upl.
PERFORM doconv TABLES itab objbin.
PERFORM ml_prepare USING 'X' extension name.
PERFORM ml_dosend.
SUBMIT rsconn01
WITH mode EQ 'INT'
AND RETURN.
FORM
FORM upl.
file_name = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = file_name
filetype = 'BIN'
TABLES
data_tab = itab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
path = file_name.
CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
EXPORTING
complete_filename = path
CHECK_DOS_FORMAT =
IMPORTING
DRIVE =
EXTENSION = extension
NAME = name
NAME_WITH_EXT =
PATH =
EXCEPTIONS
INVALID_DRIVE = 1
INVALID_EXTENSION = 2
INVALID_NAME = 3
INVALID_PATH = 4
OTHERS = 5
ENDFORM. "upl
regards,
amit m. -
How find a word in txt from Java??
Hi everybody...somebody knows how to find an especific word that is located in file txt from java somebody has the code???
Thanks in advanceHere is the code for finding a word in txt file from Java.
import java.io.*;
public class FindTextFromFile
public static String getString(String fileName)
StringBuffer fileContent = new StringBuffer(); //appending long String objects repeatedly is very costly
try
BufferedReader fileReader = new BufferedReader(new FileReader(fileName));
String line = "";
while((line = fileReader.readLine())!=null)
fileContent.append(line);
fileContent.append(System.getProperty("line.separator")); //size of line.separator=2
catch (IOException e)
e.printStackTrace();
return fileContent.toString();
public static int[] getIndicesOf(String fileName, String findWord)
String fileContent = getString(fileName);
int[] indices = new int[(int)(fileName.length()/findWord.length())]; //max possible occurances
int index=0, from=0, incr=0;
while ((index=fileContent.indexOf(findWord, from))!=-1)
indices[incr++]=index;
from=index+findWord.length();
indices[incr]=-1; //marking the end of search result storing
return indices;
public static void main(String[] args)
String fileName = "rawTextFile.txt";
String findWord = "is";
System.out.println(getString(fileName));
System.out.println();
System.out.print("Occurences of '"+findWord+"' found: ");
int[] indices = getIndicesOf(fileName, findWord);
for (int i=0; indices!=-1 && i<indices.length; i++)
System.out.print(indices[i]+" ");
Maybe you are looking for
-
How can I print a Contacts list that includes Photo in Version 8.0 (1371)
After I attach photos to selected contacts, I attempt to print in two different ways. One is to print a PDF version and the other is to go to the print command, click "details" and make sure the "photo" option is checked. Then I print in PDF. In both
-
Hi, We have implemented SRM extended classic scenario. 1) Shopping carts after approval, are getting converted to Purchase Orders (PO's), but in the web the PO status (for some only) is being displayed as "In Error". The PO is successfully replicated
-
Connections to get Audio to HDTV
I've just connected a mini display port/HDMI cable adapter to my imac, I'm getting Video display but no sound. I'm not going to bother trying any other adapters, so just wondering how I would go about getting the audio to the TV. Could I use a USB to
-
My Ipod synced and now says its my wifes Ipod, how do I get it to my settings?
I plugged my Ipod into my computer, and it started to auto sync, I stopped it before I lost all my apps, but it reconfigured my IPOD Touch to my wife's settings, including when I try to download anything it asks for her password, not mine. How do I r
-
Pass an array of a user defined class to a stored procedure in java
Hi All, I am trying to pass an array of a user defined class as an input parameter to a stored procedure. So far i have done the following: Step 1: created an object type. CREATE TYPE department_type AS OBJECT ( DNO NUMBER (10), NAME VARCHAR2 (50), L