How can I create a Document object from a text file (myFile.txt)
Hi everybody:
Thank you for reading this message.
I am trying to find a method to convert a text file ( I have it in a File object) to a Document object.
I read the Java API but it is strange, I do not know if I have to create an AbstractDocument, it is really strange for me.
Any comment is welcome,
Regards,
JB
Document is an interface, and AbstractDocument is abstract, so you
can't create either of those directly. Assuming you are dealing with a
a plain text file, you could do something like
// Not catching any exceptions that get thrown
File file = /* file you already have */
String eol = System.getProperty( "line.separator" );
int eolLen = eol.length();
FileReader reader = new FileReader( file );
BufferedReader buffer = new BufferedReader( reader );
PlainDocument doc = new PlainDocument();
for ( String line = buffer.readLine() ; line != null ; line = buffer.readLine() ) {
int len = doc.getLength();
if ( len > 0 ) {
doc.insertString( len, eol, null );
len += eolLen;
doc.insertString( len, line, null );
}and now you have a document.
: jay
Similar Messages
-
How can I read a specific character from a text file?
Hi All!
I would like to read a specific character from a text file, e.g. the 2012th character in a text file with 7034 characters.
How can I do this?
Thanks
Johannesjust use the skip(long) method of the input stream that reads the text file and skip over the desired number of bytes
-
How can I create multiple QR Codes from an Excel File?
Hi there,
I am currently trying to set up business cards with a QR Code on the back of each card. Therefore I have an excel spreadsheet, which contains all the data necessary for the business card like name, function, e-mail adress,... the data is then filled in automatically by using the standard function with tags for each column (e.g. table column name is filled in as <<name>> in the specific location on the business card and once executed it is matched with the data from the excel file).
Is there anything which could help me to automate the personalization of the QR Codes?
All the bestFor free? Not at the moment. CC does have the ability to create QR codes but only one at a time. In CS6 (perhaps earlier versions?), regular poster/advanced scripter Jongware devised a script to prepare a QR code but again, could only do one at a time.
However, someone did build on Jongware's QR code to do this from an InDesign file that had the necessary information in tagged text boxes and would prepare QR codes accordingly. However, it would leave them in the InDesign file (e.g. not separate EPS/PDFs).
So, a long workaround would be:
install the script and read the thread on the adobe forums (jongware's QR code plus the additional improvement): http://forums.adobe.com/message/4787823#4787823
data merge the current data into the indesign file using the similar structure as the fourth poster in that post had written
once all the QR codes are written, create a PDF of the file and then use one of various methods to break up the PDF into single page files: http://colecandoo.wordpress.com/2013/07/13/breaking-up-is-hard-to-do-indesign-files-into-i ndividual-pdfs-that-is/
It's a lot of work to generate multiple QR codes. A paid solution offered by either Meadows DPS or Woodwing (two companies I have no affiliation with whatsoever) or any other plug-in provider for that matter: http://www.adobe.com/products/indesign/indepth.displayTab3.html may be an alternative that is worth pursuing. -
How can i read all the lines from a text file in specific places and use the data ?
string[] lines = File.ReadAllLines(@"c:\wmiclasses\wmiclasses1.txt");
for (int i = 0; i < lines.Length; i++)
if (lines[i].StartsWith("ComboBox"))
And this is how the text file content look like:
ComboBox Name cmbxOption
Classes Win32_1394Controller
Classes Win32_1394ControllerDevice
ComboBox Name cmbxStorage
Classes Win32_LogicalFileSecuritySetting
Classes Win32_TapeDrive
What i need to do is some things:
1. Each time the line start with ComboBox then to get only the ComboBox name from the line for example cmbxOption.
Since i have already this ComboBoxes in my form1 designer i need to identify where the cmbxOption start and end and when the next ComboBox start cmbxStorage.
2. To get all the lines of the current ComboBox for example this lines belong to cmbxOption:
Classes Win32_1394Controller
Classes Win32_1394ControllerDevice
3. To create from each line a Key and Value for example from the line:
Classes Win32_1394Controller
Then the key will be Win32_1394Controller and the value will be only 1394Controller
Then the second line key Win32_1394ControllerDevice and value only 1394ControllerDevice
4. To add to the correct belonging ComboBox only the value 1394Controller.
5. To make that when i select in the ComboBox for example in cmbxOption the item 1394Controller it will act like i selected Win32_1394Controller.
For example in this event:
private void cmbxOption_SelectedIndexChanged(object sender, EventArgs e)
InsertInfo(cmbxOption.SelectedItem.ToString(), ref lstDisplayHardware, chkHardware.Checked);
In need that the SelectedItem will be Win32_1394Controller but the user will see in the cmbxOption only 1394Controller without the Win32_
This is the start of the method InsertInfo
private void InsertInfo(string Key, ref ListView lst, bool DontInsertNull)
That's why i need that the Key will be Win32_1394Controller but i want that the user will see in the ComboBox only 1394Controller without the Win32_Hello,
Here is a running start on getting specific lines in the case lines starting with ComboBox. I took your data and placed it into a text file named TextFile1.txt in the bin\debug folder. Code below was done in
a console app.
using System;
using System.IO;
using System.Linq;
namespace ConsoleApplication1
internal class Program
private static void Main(string[] args)
var result =
from T in File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TextFile1.txt"))
.Select((line, index) => new { Line = line, Index = index })
.Where((s) => s.Line.StartsWith("ComboBox"))
select T
).ToList();
if (result.Count > 0)
foreach (var item in result)
Console.WriteLine("Line: {0} Data: {1}", item.Index, item.Line);
Console.ReadLine();
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my webpage under my profile but do not reply to forum questions. -
How can I add random mail signatures from a text file?
I'm trying to add a different quote to every email that I write... is there a program or way for Mail to pluck and append a quote at random from a external file of quotes? (I'm not talking about the standard "Random" feature built into Mail.)
There must be one out there, but I can't find it. I'm using Snow Leopard and Mail 4.5Hello,
Here is a running start on getting specific lines in the case lines starting with ComboBox. I took your data and placed it into a text file named TextFile1.txt in the bin\debug folder. Code below was done in
a console app.
using System;
using System.IO;
using System.Linq;
namespace ConsoleApplication1
internal class Program
private static void Main(string[] args)
var result =
from T in File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TextFile1.txt"))
.Select((line, index) => new { Line = line, Index = index })
.Where((s) => s.Line.StartsWith("ComboBox"))
select T
).ToList();
if (result.Count > 0)
foreach (var item in result)
Console.WriteLine("Line: {0} Data: {1}", item.Index, item.Line);
Console.ReadLine();
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my webpage under my profile but do not reply to forum questions. -
How can I create a custom shape from a TIFF file?
I have a logo as a tiff file that I am trying to use as a watermark. I figured out how to insert it onto another picture through File > Place... however i then couldn't figure out how to change the colour of the watermark. Any pointers would be much appreciated!
Which version of photoshop elements are you using?
What color is the logo now?
Can you post an example of the logo? -
How to create a Document object from a string.
If I use the following code, the input String cannot contain "\n", otherwise, it generates errors.
in the following code, inputXMLString is a String object that has xml content.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(inputXMLString))); How can I create a Document object from a string with "\n" in the string?
Thanks.If I use the following code, the input String cannot
contain "\n", otherwise, it generates errors.That's going to be a huge surprise to thousands of people who process XML containing newline characters every day without errors.
Perhaps your newline characters are in the middle of element names, or something else that causes your XML to be not well-formed. I'm just guessing here, though, because you didn't say what errors you were getting. -
How can I create a single order from multiple quotations?
How can I create a single order from multiple quotations that I have created by the transaction VA21 ?
Thanks in advance for the answers.hi
Go to transaction: /nva01
Enter order type : ZOR
Sale org :xxxx
Dist.channel:xx
Division :xx
Press enter
Click on Sale document and select Create with reference
Then enter 1st quotation number & click on COPY or Selection list. Then click on Copy .Then all line items which belong to quoation1 copy to order.
Then,
Click on Sale document and select Create with reference
Then enter 2nd quotation number & click on COPY or Selection list. Then click on Copy .Then all line items which belong to quoation2 copy to order.
Then,
Click on Sale document and select Create with reference
Then enter 3rd quotation number & click on COPY or Selection list. Then click on Copy .Then all line items which belong to quoation3 copy to order.
Now save the sale document.
Kindly give reward points
Edited by: WISH on Mar 19, 2008 2:25 PM -
How can i create a custom object 0REQUID
Hello all,
I have a question. How can i create a custom object 0REQUID? Is it possible to create it without actvating BI content?
Thanks in advance..Hi,
If you want to create a new info object which is a copy of 0REQUID. then
Go to > info object key figure / Chara catalogue> create new key figure / Chara --> enter 0REQUID in front of TEMPLATE and you will get all details of 0REQUID in your new key figure / chara.
Hope this helps.
Assgn pts if helpful.
Regards
Edited by: chintamani deshmukh on Apr 14, 2008 11:09 AM -
How can I create an audio CD from the audio only portion of my iMovie?
Hello, I brought in about 50 min of Digital video into iMovie, I separated (split) the audio from the video, I unlocked the audio, I deleted the video, and now I want to just create an audio CD from the audio that is left.
Can I do this? and if yes how? If I can not, how can I create an Audio CD from on my G5 off a tape on my digital camcorder?
Any help would be apprecaited.This is how:
Go to:
'File'
'Share'
'Quicktime'
'Expert Settings'
'Audio as AIFF' or pick your brand of compression.
Drag and drop the resulting file into iTunes.
Enjoy!
P.S. - You didn't need to delete the video but I think that'll be okay. -
HT201441 how can i create and audio cd from a music track I have on my ipod
how can i create and audio cd from a music track I have on my ipod
This is how:
Go to:
'File'
'Share'
'Quicktime'
'Expert Settings'
'Audio as AIFF' or pick your brand of compression.
Drag and drop the resulting file into iTunes.
Enjoy!
P.S. - You didn't need to delete the video but I think that'll be okay. -
How can I drop the java objects from a schema
hi..good afternoon all...
How can I drop the java objects from a database schema???
suppose the credentials are scott/tiger@db1
Another thing is that...I have to do this from cmd(command prompt) as there is no plsql developer or sqldeveloper installed in the machine.
plss help...thanks in advance...hi...i have already tried all the options..but it is showing the error..
ora:01435 - user does not exist
but when i have given the command...
select object type, object_name, status from user_objects where object_type like'%JAVA%';
then it is showing that the java_object is present....
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
SQL>
SQL>
SQL> set linesize 200
SQL>
SQL>
SQL>
SQL> select object_type, object_name, status from user_objects where object_type
like '%JAVA%';
OBJECT_TYPE OBJECT_NAME
STATUS
JAVA CLASS javaclass1
VALID
JAVA SOURCE javaclass1
VALID
SQL> drop java source javaclass1.java;
drop java source javaclass1.java
ERROR at line 1:
ORA-01435: user does not exist
SQL> -
How can we create a ABAP object into .ptr file
HI,
How can we create a ABAP object into .ptr/.car/.sar format so that we can give it to a remote client and which can be imported into their R/3 system to get the functionality of this object.Hello Ramesh
All you need is SAPLINK. Have a look at the following links:
<a href="/people/ed.herrmann/blog/2005/11/14/the-enterprise-and-the-bazaar Enterprise and the Bazaar</a>
<a href="https://sourceforge.net/projects/saplink/">SAPLINK</a>
Regards
Uwe -
Using pages, how can I create a label run from contacts
Using pages, how can I create a label run from contacts?
You mean you want to use XML to create a flat file, right? Not that the database is using XML in some way? If so, why do you want to use XML?
-
How can i get the all values from the Property file to Hashtable?
how can i get the all values from the Property file to Hashtable?
ok,consider my property file name is pro.PROPERTIES
and it contain
8326=sun developer
4306=sun java developer
3943=java developer
how can i get the all keys & values from the pro.PROPERTIES to hashtable
plz help guys..............The Properties class is already a subclass of Hashtable. So if you have a Properties object, you already have a Hashtable. So all you need to do is the first part of that:Properties props = new Properties();
InputStream is = new FileInputStream("tivoli.properties");
props.load(is);
Maybe you are looking for
-
Why will a Leopard backup DVD not work on G5.
A couple of Leopard issues: 1, When I a make a dvd backup of my Leopard dvd using either Disk Utility or Toast it will work fine on the intel but will be spit out of the G5. The G5 cannot make double layer so I must rely on a computer that does! My G
-
When I go into Tools, Options, Privacy and set 'Use custom settings for history' and then click okay it will not save. It stays on 'Remember history', though it will save 'Never remember history' as I tested this. This seems to have happened after re
-
This error message only come up on my ipad since the shift to ios7. It doesn't happen on my iphone 5, just my ipad. It's a 3rd generation. If I uncheck sync photo's it works fine? If check photo's it comes up with the error message. Its a real pain a
-
hi everybody I have added 2 additional fields(zzqty, zzprice) at item level in PO, Ive also added the subscreen in me21N My requirement is that these 2 fields should be copied from the fields menge and netpr for each line I have coded the following i
-
Is it necessary to have both installations, ps cc and ps cc(2014) on my pc, or can I deinstall the older version?