I/O / Streams :: Escaping Double Quotes Be Applied To Reading From A File?
Sep 26, 2014
If I'm using an xml file and the piece of data I want from the file looks like Staff id ="Test";
Is it something like this? Only seen two examples of it but I'm not sure they were reading from a file like myself.
Staff id = """ + Test + """;
View Replies
ADVERTISEMENT
Jan 5, 2015
I'm learning jQuery to integrate into a JSF application but finding some confusion on the correct syntax especially when it comes to combining double and single quotes in the jQuery scripts. So for this particular page I want jQuery to traverse through a list of documents and put icons next to each document to state what type of document each is (ie: PDF, doc, xls). I can get this to work using normal html markup but I get a Syntax Error - Unexpected Token exception in the browser.
I'm confused about whether this means I need to use the right html references for the JSF element I wish to traverse or whether this is a problem with the way I'm using my quotes.
Also I'm not sure how to correctly reference jsf tags inside jQuery scripts. So for an ordinary html page I execute the following jQuery script:
<script type="text/javascript">
$("document").ready(function () {
$("li a[href = ' .pdf']").after("<img src='myImage'/>");
});
</script>
</code>
Then I have a JSF page with the following commandLink:
<p:column>
<p:commandLink class="downLoadLink" value="Download" ajax="false">
<p:fileDownload value="#{projectDocBean.downloadedFile}"
contentDisposition="attachment"/>
</p:commandLink>
</p:column>
For this page I try to execute the following script:
<script type="text/javascript">
$("document").ready(function () {
$("#downLoadLink = ' .pdf']").after("<img src='myImage'/>");
});
</script>
I get the same syntax error no matter what I put into the script of the JSF page. How to correctly integrate jQuery with JSF.
View Replies
View Related
Mar 17, 2014
how to replace all the command that is found on a string between 2 double quotes? for example I have a text file that contains data like as following
A,"-16,12","-178,245","-15,506"
B,"-16,12","-178,245","-15,506"
C,0, 0,1
I need an output like this:
A,"-16.12","-178.245","-15.506"
B,"-16.12","-178.245","-15.506"
C,0, 0,1
I did this but without regular expression. It seems to me that a regular expression it's more elegant than to parse every line and replace it.
View Replies
View Related
Oct 11, 2014
I'm having a bit of trouble with using the Scanner and the Printwriter. I start with a file like this (1 = amount of Houses in the file)
1
FOR SALE:
Emmalaan 23
3051JC Rotterdam
7 rooms
buyprice 300000
energylevel C
The user gets (let's say for simplicity) 3 options:
1. Add a House to the file,
2. Get all Houses which fullfil requirements (price, FOR SALE / SOLD etc.) and
3. Close the application.
This is how I start:
Scanner sc = new Scanner (System.in);
while (!endLoop) {
System.out.println("Make a choice);
System.out.println("1) Add House");
System.out.println("2) Show Houses");
System.out.println("3) Exit");
int choice = sc.nextInt();
Then I have a switch for all of the three cases. I keep the scanner open, so Java can get the user input (house = for sale or sold, price = ... etc). If the user chose option 1, and all information needed is inputted and scanned, the House will be written to the file (which looks like what I typed above).
For this, I use try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("Makelaar.txt", false)))). This works perfectly (at least so it seems.)
If the user chose option 1, and all requirements are inputted and scanned, the Houses will be read (scanner) from the file and outputted. For this I use the same Scanner sc. This also works perfectly (so it seems atleast).
My problem is as follows: If a House has been added, I can only read the House(s) which were already in the file. Let's say I have added 2 houses, and there were from the start 3 houses. If option 2 is chosen, the first 3 houses will be scanned perfectly. An exception will be caught for the remaining 2 (just added) Houses. How can I solve this? I tried to close the Scanner, and reopening it, but apparently Java doesn't agree with this
View Replies
View Related
Oct 15, 2014
If I want to read my file line by line and when it hits a certain value from that point it should start deleting the lines until the tag ends.Just curious will my code actually work at the moment or not because it goes through so many times then goes straight back to the variable declarations at the start of the method and never hits the console print line.
public void removeEnvironment(){
//declare variable to environment id
String environmentID = "Environment id";
String lines = null;
boolean lineFound = false;
boolean end = false;
[code]...
View Replies
View Related
Apr 1, 2014
How to maintain quotes in a text file? If no source files .
Новый точечный .jpg
Prompt in what direction to go .... maybe you can use other languages to do it?
Заранее СПасибо!!!
View Replies
View Related
Sep 17, 2014
I have a code below that is reading large image size and writing them to file however the process is too slow. how can i refine this code in such a way that it will work faster?
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.HttpURLConnection;
[code]....
View Replies
View Related
Dec 6, 2014
I'm trying to synchronize two folders and their sub directories between a client and a server. I have a modified version of this class which I've posted below. In my Client class, I create a WatchDir object and call its processEvents() method in an infinite loop. The method returns a myTuple object (a struct containing the event type and a path object) if an event is registered and null if not.
The problem is that this only seems to work for the first event to happen in the directory (i.e. if I add a file to the watched folder, my WatchDir object.processEvents() returns one Tuple with an ENTRY_CREATE event and never returns another Tuple for other file additions/deletions/modifications that happen after). I'd like for processEvents to be continuously called (hence the infinite while) returning a Tuple each time some event occurs.
My modified WatchDir:
import static java.nio.file.StandardWatchEventKinds.*;
import static java.nio.file.LinkOption.*;
import java.nio.file.attribute.*;
import java.io.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
[Code] ....
View Replies
View Related
Mar 22, 2014
I have a text file that has contents as follows:
testing1,true,0,0.0,0,0.0,4.0,0.0,0.0,0.0,0.0
test2,true,0,0.0,0,0.0,4.0,0.0,0.0,0.0,0.0
I am trying to read only the first item in each list using a comma as a delimiter using the following code.
public String[] pList() {
ArrayList<String> names = new ArrayList<String>();
String word;
try {
String path = P_FOLDER + P_FILE;
[Code]....
View Replies
View Related
Sep 17, 2014
I have a code below that is reading large image size and writing them to file however the process is too slow. how can i refine this code in such a way that it will work faster?
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.HttpURLConnection;
[code]...
View Replies
View Related
Apr 22, 2014
I am creating a web application that runs on server X(unix) and it has another unix system mounted on it. I want to generate the file tree structure of this mounted unix file system and show it on to a web application so that users can select a file and move it onto this current unix machine.
I know this sounds stupid and you may want to say why cant we directly copy the file, I am doing a proof of concept and using this as a basis.
View Replies
View Related
Jun 25, 2014
Let's say I have a text file and in the text file exists file directories as such:
'assets/picture1.png'
'assets/picture2.png'
And so on...
How would I then read from this text file and then create those files using 'new File()'?
Here is my code:
private void getFiles() throws IOException{
files = new File[10];
Scanner scan = new Scanner(new File("files.dat"));
int count = -1;
[Code]....
It does print out those files, but it doesn't create them.
View Replies
View Related
Sep 22, 2014
I know that it's possible to retrieve a line from a txt file but say for example my file looked like this:
staff id = 1
firstname
surname
age
staff id =2
firstname Kate
surname Hollar
age 33
staff id =3
firstname Daniel
surname Hong
age 21
It is possible to retrieve just the staff id's?
View Replies
View Related
Aug 12, 2014
I have a code that clear old text then add new text to text file afterthat download the file but the problem my code dose not add new text
FileInputStream fileToDownload ;
private static final int BYTES_DOWNLOAD = 1024;
response.setContentType("text/plain");
String name = request.getParameter("n");
String text = new String(request.getParameter("text").getBytes("iso-8859-1"), "UTF-8");
[Code] ....
How to clear old text then add new text to text file
View Replies
View Related
Aug 25, 2014
I have a problem with € symbol ... an application write a String content on the file system with following code:
out = new FileOutputStream(strPath + "import.xml");
out.write(trp.getTrpXMLModel().getBytes("ISO-8859-1"));
It's correctly wrote on the file system:
TT;Pierre-H€enri;;Orange Grove;zefezfezfez, Directeur Juridique;TT;;azdaz;01 53 33 56 87;ezfezfez;01 53 33 51 59;.....&ée&ée;;;;;;132;CORDIAL;aaa
But when the application try to read the previous file with following code:
BufferedReader in = new BufferedReader(new InputStreamReader(inStream,"ISO-8859-1"));
String line = in.readLine();
The application isn't able to properly read the symbol ... and return following line, without "€":
TT;Pierre-Henri;;Orange Grove;zefezfezfez, Directeur Juridique;TT;;azdaz;01 53 33 56 87;ezfezfez;01 53 33 51 59;.....&ée&ée;;;;;;132;CORDIAL;aaa
View Replies
View Related
May 20, 2014
I would like to create a component to detect the file being modify before process.is it the right way to detect the file modification based on file size value?
Below are the flow:
1. Get the file size of a file
2. Used file size value encrypt it with MD5 algorithm, and say it generated us encrypted value "0123sdf"
3. to avoid user modify the file content, before file process, we take the file and do the encryption with md5 again, if it return value "0123sdf", then we are sure it doesn't have modification.
my question:
a. is it the right approach to detect file modification?
b. what the library advise to use or using java.security.DigestInputStream will do?
View Replies
View Related
Jul 30, 2006
I want to create hidden files, some sample code for doing this.
View Replies
View Related
May 13, 2012
I am looking for a pure java api that can read metadata from an mp4 file, I have looked online but all apis I found are wrappers to native code. How to read mp4 with java .....
View Replies
View Related
Jul 17, 2014
I have a log file which goes like this..
INFO: Jul 07 00:00:15 DataSource 2zvw8p93107gev14wko86|34e51ca2: Total connections 4 idle 4 busy 0 unclosed orphans 0 pool unknown
PERFORMANCE: Jul 07 00:00:15 Garbage Collection: ParNew 5 51ms in 59 seconds. [SpeedoLoggingBean] Thread SpeedoBean
INFO: Jul 07 00:00:15 Speedo: 2,222,786K of 4,054,528K - 1,831,741K free, 4,952epm, 1 buffered, 216 threads, 49.1% CPU, permgen 173,731K of 262,144K - 88,412K free
Jul 7, 2014 12:00:15 AM org.geotools.data.wfs.v1_0_0.WFSTransactionState commit
SEVERE: number of fids inserted do not match number of fids returned by Transaction Response. Got:1 expected: 0
[code].....
What I need is to grab only the last hour data from this log file?
View Replies
View Related
Nov 8, 2014
I have a binary file that has identifiers for the start of each record
You can see here that the record starts with 00 00 and the next record starts with 00 00 etc...
How do I read between these two points throughout the file?
RandomAccessFile database = new RandomAccessFile(databasePath, "r");
int start = 0;
int end = 0;
database.setLength(start);
database.seek(end);
The first start would be the start of the file, the next start would be the end of the first start and so on..
I'm just not sure how to put that into a loop.
View Replies
View Related
Aug 28, 2014
I have been going over my code line by line, over and over again for nearly and hour now...When I execute method `file.createNewFile()`, the method returns true and throws no exceptions. It even says that the file exists. However, the file is not created and cannot be accessed until the program has exited.
File portLib = new File("");
private class RememberPortAction extends AbstractMenuItemAction
{
methods...
protected void actionPerformed() {
LibraryCreator creator = new LibraryCreator(self, logger);
File newPortLib;
[code]....
View Replies
View Related
May 25, 2014
My program creates a file but cannot write to it and i cannot figure out why.
How can i fix this code so that the FileOutputStream writes the String "Output" to the file HighScore.
public boolean ScoreWriter(int HighScore, int ScoreNum){
boolean writ = true;
System.out.println(HighScore + " " + ScoreNum);
try{
File ScoreFile = new File("HighScore");
if (!ScoreFile.exists()){
ScoreFile.createNewFile();
}else if (ScoreFile.exists()){
ScoreFile.delete();
ScoreFile.createNewFile();
[code].....
View Replies
View Related
Jul 24, 2014
I do most of my file I/O with {Scanner} for input and {PrintWriter} for output. I've got lots of places in my code that looks like:
Scanner source = new Scanner( new File( sourceName));
PrintWriter dstntn = new PrintWriter( new BufferedWriter( new FileWriter( dstntnName)));
But when I call the constructor for {PrintWriter} up above, it overwrites whatever the original contents of the file designated by {dstntnName} were, doesn't it? Is there a way to call the constructor so that any future writes to it simply append to the original contents, instead of overwriting them?
View Replies
View Related
Oct 23, 2014
When my app starts up is it possible to create a blank xml file in the c drive? so I can use it later on down the line
View Replies
View Related
Feb 7, 2006
I have to divide a text file into blocks of 128 bits. I think i must use the ByteArrayInputStream and ByteArrayOutputStream classes. is there any website showing how to user these two ByteArrayInputStream and ByteArrayOutputStream classes in detail. or it would be much better if you could show me a portion of the code.
View Replies
View Related
Dec 9, 2014
I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...
The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data. Here is the base Product class that must be used to create the objects for the array.
public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;
[Code]...
these continue for about 40-50 entries, they are not seperated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name seperated with spaces, then price after a comma, then quanity after the second comma.....
View Replies
View Related