Yes, There's More Than One Way To Do It™, but what is the most canonical, most efficient, and most concise methods to read an entire file into a string? (The latter two are perhaps at odds.)
I have a plain text file with words, which are separated by comma, for example:
word1, word2, word3, word2, word4, word5, word 3, word6, word7, word3
i want to delete the duplicates and to become:
word1, word2, word3, word4, word5, word6, word7
Any Ideas? I think, egrep can help me, but i'm not sure, how to use it exactly....
I need to be able to download some file from a regular site using my proxy server,
I already try this:
System.Net.WebClient client = new System.Net.WebClient();
client.Proxy = new WebProxy(ip, port);
client.DownloadFile(url);
but it's not works at all, I don't know what I missed,(without a proxy it works)
thanks,
Dani.
I am a unclear about file system implementation. Specifically (Operating Systems - Tannenbaum (Edition 3), Page 275) states "The first word of each block is used as a pointer to the next one. The rest of block is data".
Can anyone please explain to me the hierarchy of the division here? Like, each disk partition contains blocks, blocks contain words, and so on...
Say I have file A, in middle of which have a tag string "#INSERT_HERE#". I want to put the whole content of file B to that postion of file A. I have tried using pipe to concatenate those contents, but I'm wondering if there is more advanced one-line script to handle it.
Thanks.
We can replace strings in a batch file using the following command
set str="jump over the chair"
set str=%str:chair=table%
These lines work fine and change the string "jump over the chair" to "jump over the table". Now I want to replace the word "chair" in the string with some variable and I don't know how to do it.
set word=table
set str="jump over the chair"
??
Any ideas?
I didn't think this was going to be hard. I have a commmand file, d:\a.cmd which contains:
copy /b d:\7zS.sfx + d:\config.txt + d:\files.7z d:\setup.exe
But this line of C# wont' execute it:
Process.Start("d:\\a.cmd");
Throws Win32Exception: "%1 is not a valid Win32 application."
Process.Start opens .pdf files...why not execute command files?
Thanks in advance,
Jim
I have a file and I don't know how big it's going to be (it could be quite large, but the size will vary greatly). I want to search the last 10 lines or so to see if any of them match a string. I need to do this as quickly and efficiently as possible and was wondering if there's anything better than:
s = "foo"
last_bit = fileObj.readlines()[-10:]
for line in last_bit:
if line == s:
print "FOUND"
I want to throw the last three character from file name and get the rest?
I have this code:
char* remove(char* mystr) {
char tmp[] = {0};
unsigned int x;
for (x = 0; x < (strlen(mystr) - 3); x++)
tmp[x] = mystr[x];
return tmp;
}
I want to pass a command as a command line argument from one batch file to another
e.g.
first.bat
call test.bat "echo hello world" "echo welcome "
test.bat
set initialcommand=%1
set maincommand=%2
%maincommand%
%initialcommand%
Hi
I'm trying to get an SQL query to work within a JSP file. The JSP file is pulled by a VXML file here is my JSP file code:
<?xml version="1.0"?>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<% boolean success = true; // Always optimistic
String info = "";
String schoolname = request.getParameter("schoolname");
String informationtype = request.getParameter("informationtype");
try {
Class.forName("org.postgresql.Driver");
String connectString = "jdbc:postgresql://localhost:5435/N0176359";
String user = "****";
String password = "*****";
Connection conn = DriverManager.getConnection(connectString, user, password);
Statement st = conn.createStatement();
ResultSet rsvp = st.executeQuery("SELECT * FROM lincolnshire_school_information_new WHERE school_name=\'"+schoolname+"\'");
rsvp.next();
info = rsvp.getString(2);
}catch (ClassNotFoundException e) {
success = false; // something went wrong
}
%>
As you can see I'm trying to insert the value of the variable declared as "schooname" into the end of the SQL query. However when I come to run the jsp file it doesn't work and I get an error "ResultSet not positioned properly". When I put a standard query in (without trying to make it value of the variable it works fine)
Hope that makes sense, and thank you for any help!
I am attempting to decompress a .gz file using the GnuWin32 gzip program in Windows 7. I have full permissions on the compressed file, and my user account is an administrator. However, I end up not having read permissions on the decompressed file. To get read permissions I would have to manually change the permissions on it through right-clicking and selecting Properties Security. I am able to do this exact same thing with no permission problems in Windows XP, which leads me to believe that Windows 7's user account control system is causing problems. Does anyone know what I can do to make things work as I would expect (read permission on the decompressed file) in Windows 7?
Thanks.
I have a process "x" which uses "system" C function to start ntpd daemon. I observed that ntpd are passed the open file descriptors of "x". ntpd holds on to the file descriptors even after original file is deleted. for ex: Some log files used by "x" are rotated out after sometime, but "ntpd" has file handle opened for these deleted files. Will it cause any problem?
Alternatively I thought of setting "FD_CLOEXEC" flag for all the file descriptors before calling "system" function. But as we are running as an extension library to third process "x"( "x" loads our library based on some condition), there is no easy way to know about all the file descriptors process has opened. One way is to read /proc//fd and set "FD_CLOEXEC" for each file handle and reset it back after "system" function returns. I'm using Linux 2.16. Is there any other easy way to find all the file handlers?
Thanks,
I have a large file (hundreds of megs) that consists of filenames, one per line.
I need to loop through the list of filenames, and fork off a process for each filename. I want a maximum of 8 forked processes at a time and I don't want to read the whole filename list into RAM at once.
I'm not even sure where to begin, can anyone help me out?
Heya! My name is Ale, and this is the first time that I post in this website.
I've a little problem: I have to open a linker file, that have ".a" extension. I use Dev-C++, I don't know if it would be useful for you :-P
I hope you will answer soon!
Oh, and excuse me for my bad English, tell me if I made some mistakes!
Thanks!!
Hi,
I want to convert the mysql database table contents to an Excel(.xls) or comma seperated file(csv) using python script... Is it possible? Any one can help me?
Thanks in advance,
Nimmy
How to transfer a file greater than 100mb using spring mvc.
I have been through the post http://stackoverflow.com/questions/214888/how-to-handle-100mb-uploads-for-users, that tells to use ftp api. But want to know an alternative with spring.
Is there a way to queue file uploads without resorting to Flash or Silverlight, just with cleverly used forms and JavaScript? Note that the upload should be executed asynchronously.
By "queuing" uploads I mean that if the user tries to upload multiple files, they should not be transferred simultaneously, but rather one at a time, in a single HTTP connection.
Using Canvas method toDataURL, I would like to be able to save the image on the server side (using Rails).
With toDataURL string, how to use it in a form that can be seen as a file attachment in a HTML form ?
this is my error code:
text = open('/media/a.txt', 'rb').read()
and my perplexed is:
when i use this :
text = open('a.txt', 'rb').read()
it can be running
but when i put the 'a.txt' to the 'media' folder, i can't running ,
why ?
thanks
IOError at /
[Errno 13] file not accessible: '/media/a.txt'